By gsgchoi on
Hi, in my page.tpl.php,, my breadcrumb displays perfectly in each page by calling "print $breadcrumb".
Now I am trying to get this $breadcrumb variable in my custom module by using node ID. Is there any way I can grab the corresponding $breadcrumb value to given node ID (nid).
Basically, what I am trying to do is to display all the contents/nodes in my site and display its breadcrumb in the next column.
I tried something like below, but it didn't work.
$page_node = node_load($r->nid);
print $page_node->breadcrumb;
Please help!
Edited by WorldFallz - moved to appropriate forum.
Comments
You could use the
You could use the drupal_get_breadcrumb function. Here's the API documentation for it. http://api.drupal.org/api/function/drupal_get_breadcrumb/5
EDIT:
You can also use template_preprocess_page to modify this variable if you wished.
Thanks for your help! I was
Thanks for your help!
I was just wondering how I could use "drupal_get_breadcrumb" to get each node's breadcrumb data. "drupal_get_breadcrumb" doesn't look like that it gets any parameter such as nid. I am looking for something like "drupal_get_breadcrumb($nid)" so it can return the corresponding breadcrumb dynamically.
For your information, I am working on a page/module (eg. mymodule.module) where I simply do a database select statement (select n.title, n.nid from node n where n.status = 1)... then in the page (eg. http://mysite.com/mymodulepage), I display title of node in the 1st column, and nid in the 2nd column. And I want to append 3rd column displaying its breadcrumb.
I am new to Drupal, I would appreciate if you could help me a bit further.
If you need more information, please feel free to let me know!
Node's aren't part of the
Node's aren't part of the breadcrumb in Drupal, as they are essentially 'orphaned items'. However, you can add the node to a particular menu, and then use the Menu Breadcrumb module, and in that way the node will become part of the breadcrumb.
However, you could get the breadcrumb using drupal_get_breadcrumb, and append the node yourself on the end of it, giving you a breadcrumb to your node.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for your information.
Thanks for your information. I am sorry that I can't fully understand your suggestion since I am not yet familiar with Drupal.
I want to show you what I have right now and hope this allow you to give me some code example.
//In mymodule.module
function mymodule_menu() {
$items = array();
$items['mystats'] = array( //http://www.mysite.com/mystats is where I want to display the table containing a list of nodes (title, breadcrumb and etc)
'title' => 'My Site Stats',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
'page callback' => 'domystats'
);
return $items;
}
function domystats() {
......
.....
$result = db_query("SELECT n.nid, ua.dst, n.title FROM {node} n INNER JOIN {url_alias} ua ON ua.src = CONCAT( 'node/', n.nid ) WHERE n.status = 1 ORDER BY n.type, n.changed DESC");
$total_rows =db_result($result);
while($r = db_fetch_object($result)) {
if ($r->dst != 404 && $r->dst != 403) { //Skip error pages
$page_url = $base . $r->dst; //$base is my domain
$bc = drupal_get_breadcrumb(); //This does not return the breadcrumb of node with the $r->nid since drupal_get_breadcrumb returns the breadcrumb of current page which is /mystats
$output .= "
$page_url :: $r->title :: $bc
";
}
}
....
...
return $output
}
Basically that's pretty much of all I have so far and now I just need to find a way to get each page's breadcrumb that is being displayed by the "print $breadcrumb;" in page.tpl.php
I would appreciate if you could give me some code example or put your comment/code in the above source code.
Thank you so much!