get nid's that contain current url_alias

Created on 15 April 2011, about 14 years ago
Updated 12 March 2024, about 1 year ago

Hi everyone.

I'd like to start with saying my php knowledge isn't vast, but I do what I can.
I've also been searching here and on google for methods to do this, I think I'm close. Here goes!

I have installed the coda slider module, and I am using views to display a slider under the content of a page. I would like all content being brought in to said view to be done using the current URL_alias. I currently have tried views_embed_view to get it working- and it does... but it does not use the coda module and just displays all nodes in a list. If someone can help me reformat the code so that it will work in the PHP Validation box under a Node: ID argument, or point me in the right direction that would be great;

below is what I've pasted into my page.tpl.php to see if it works, and it does- but doesnt use the coda slider properly (or at all).

// get the path of the current page
$current_path = drupal_get_path_alias($_GET["q"]);

// find the source URL from all database url_alias table entries that contain $current_path within their string
$url_source = db_query("SELECT src FROM {url_alias} WHERE dst LIKE '%$current_path%'");

// assign $nodes array to store the values, and then store the data from the query result to the $nodes array.
$nodes = array();
while($paths = db_fetch_array($url_source)) {
  $nodes[] = $paths['src'];
}

foreach ((array)$nodes as $node) {
	$url = explode("/", $node);
	// output each of the node id's by exploding the array of values at each slash
	$nids[] = $url[1];
	// take the second array value from each, which would be the node id number.
};

// put all arguments together, separated by commas
$argument = implode("+", $nids);

// pass argument to views and load into template file:
$output = views_embed_view('node_slider', 'block_1', $argument);
if ($output){
print $output;
}

This seems to work.

Essentially what I'm trying to do is get the views php validation code to look into the db, find url_aliases that begin with the current url_alias, get the node/## url from the src table from all matching entries. get the nid number from all extracted src_urls, and then pass them to the Node: ID argument in views.

Reason being is that I would like the client to have a simple way to just add pages to the slider by just adjusting the URL rather than using taxonomy and wondering what all these buzz words are.

💬 Support request
Status

Fixed

Version

2.9

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024