By bwooster47 on
I did search Drupal web site for this, but after a hour, unable to sort this out.
Given a Drupal path (or alias, but I can use drupal_lookup_path() to go between them), how can I get the title of that path?
For example, given node/99 or forum/47, is there a way to get the title?
Probably menu_get_item()?
menu_get_item(NULL, 'node/99') returned empty array, so not sure if there is some other issue in the way I am calling it, or if this is not the way to do it.
Any pointers appreciated.
Comments
--
drupal_get_title...? http://api.drupal.org/api/5/function/drupal_get_title
That will give you something like 'Content' on the front page... and the taxonomy term on term pages.
And the title of the node on a node/x page.
Caroline
A coder's guide to file download in Drupal
Who am I | Where are we
11 heavens
Current yes, but remote?
Mmm. That's get the current page title.
I think the request here is to find the title of the target of other referenced links, given just their path - such as by making a filter that annotates any hrefs with the title="" alt value as found by introspecting the system.
Hm, doesn't this already exist?
Good question, sorry I can't think of a quick answer OTTOMH.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
mmmmmmmmmm
yeah... right
hey dman how ur doing by the way
(funny, whenever I imagine you, I see you with a shaker on the other side of a bar, I wonder if it's something I read somewhere...)
Lost Caroline
Who am I | Where are we
11 heavens
can't find anything
OTTOMH = ?
Out of the tip of my hand ?
=-=
OTTOMH = Off The Top Of My Head
No, but dman is a magician,
No, but dman is a magician, doh.
Caroline
Who am I | Where are we
11 heavens
Yeah, That's me
Yeah, That's me ;-)
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Don't mean to scare anyone.
Don't mean to scare anyone. I am not that much of a clairvoyant.
I've been on your site a while ago, that's where I got the visual from, I think.
I hadn't seen that, though. Very Kewl dman...
Caroline
Who am I | Where are we
11 heavens
How about...
I needed this too. Try this:
This could probably use some code suggestions/cleanup from you more experienced PHP developers.
Yeah I think the way to do
Yeah I think the way to do it is to use menu_get_item, and I even think that you're calling it correctly.
Have you tried with 'TRUE'....?
menu_get_item(NULL, "node/43", TRUE);
Does that return an empty array?
Caroline
Who am I | Where are we
11 heavens
Yes, that is empty too - this is not as simple as I thought.
I think I am beginning to understand that what I need is not that easy - impossible, perhaps!
The issue is that I'm looking for a way to get title of what would be displayed given a Drupal path - which can be a menu item, a forum, a comment, for example:
node/281
node/281#comment-31
forum/11
taxonomy/term/18/9
The menu system handles this using callbacks at different levels of the menu - therefore, the only way to get this may be to execute the menu traversal that Drupal index.php performs.
Or, use HTTP to connect to the server and do a GET on the URL above !!!
Add to this, the menu path such as taxonomy/term/18/9 is clearly not a node - though it does have a title that can be used to display that page.
So, starting to understand why this seemingly simple request is not so simple.
No solution yet... (other than HTTP GET and look at title returned!)
Look at menu.inc
Look at the function "menu_execute_active_handler" from menu.inc - pasted below...
The first part finds the menu callback that matches the current location. From that, you can find the default title for the callback. If the callback changes the default title, you'd have to execute the callback to get the correct title. Seems like a good thing to cache and update after edits rather than doing at display time...
http://www.trailheadinteractive.com
--- Featured Projects ---
http://www.montanakitesports.com
http://www.cmrussell.org
http://www.tdandh.com
http://www.cccsmt.org
http://www.universalsemensales.com
http://www.trailheadinteractive.com
Following works with Primary
Following works with Primary Links:
--
(3 John 1:2) Dear friend, I pray that you may enjoy good health and that all may go well with you, even as your soul is getting along well.
--
DevElCuy
possible solution
See How to get node object from a path? for another possible solution - will work for Drupal node paths only though, not for any other Drupal paths (like term/..., taxonomy/...)
Summary of the Drupal node lookup-solution:
Do a drupal_get_normal_path and then a node_load to get node object, which as all the node data, including title.
Or, use SQL:
Load a node using its path...
$path = drupal_get_normal_path('my/fancy/path/node');
$node = menu_get_object('node', 1, $path);
print $node->title;
That won't work in Drupal 4.7
That won't work in Drupal 4.7 (which is the version this thread refers to).
Contact me to contract me for D7 -> D10/11 migrations.
Drupal 7 Method
For anybody still trying to do this for Drupal 7, here's a quick solution:
$item = menu_get_item('path/to/menu/item');
print $item['title'];
Documentation on menu_get_item() is at http://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_i...
Check for system path (D7)
The above D7 quick solution works fine, but not with aliased paths.
To make it cope with aliases, you have to check for the system path first:
Not working on View page
It is working fine in normal node but it is giving blank title in view page. Any suggestions.
Some of the world's greatest feats were accomplished by people not smart enough to know they were impossible...- Doug Larson
Depending on the type of
Depending on the type of page, the $item will be a different type of object. nodes (and probably panels) have 'title' but I think a view (and maybe a user or a term) would have a 'name' instead. It will vary.
What you should do is
* get and enable devel.module
* enter dpm($item); in the code at that point to see what the structure returned looks like.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
On node and views
That gave me results on nodes and views
hope someone will find it useful