Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output <?php get_parent(); ?> without hyphen in template
#5
I had the same problem - but im not very happy with your solution.
You mix up URL-Slugs with navigational elements.

I tried to get the Title/Menutext of the parent page with menu_data() as following:

Code:
# output page_slug for toplevel menu entries and parent_slug for sublevel items

#get parent Title via menu_data()
$parentdata  = menu_data(get_parent(false));

# check if PARENT title exists (>0)
if ( strlen($parentdata['title']) > 0 )
    {
    # show parent menu_text or fallback to title (as menu_text seems empty if same as title)
    if (strlen($parentdata['menu_text'])>0) {echo $parentdata['menu_text'];} else {echo $parentdata['title'];}
    }
    else
        {
        # or show CURRENTPAGE menu_text/title
        $seite = return_page_slug();
        $pagedata = menu_data($seite);
        if (strlen($pagedata['menu_text'])>0) {echo $pagedata['menu_text'];} else {echo $pagedata['title'];}
        }

this is doing what i want - but is there an easier way to get parent-element infos?
(sth. like "is_child" or "is_parent" would be quite helpful)
Reply


Messages In This Thread
output <?php get_parent(); ?> without hyphen in template - by igestalten - 2012-03-24, 02:37:32



Users browsing this thread: 1 Guest(s)