GetSimple Support Forum
output <?php get_parent(); ?> without hyphen in template - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Themes (http://get-simple.info/forums/forumdisplay.php?fid=10)
+--- Thread: output <?php get_parent(); ?> without hyphen in template (/showthread.php?tid=2343)



output <?php get_parent(); ?> without hyphen in template - Connie - 2011-11-05

I need a hint how to omitt hyphen in parent ..

example:

I have a first level page "my cats"
Slug/URL is "my-cats"

Now I have a second-level-navigation in the sidebar and want to repeat the parent, like category
before the submenu

unfortunately

Code:
<?php get_parent(); ?>
outputs "my-cats" instead of "my cats"

what can I do to omitt this?


output <?php get_parent(); ?> without hyphen in template - Connie - 2011-11-05

I found a solution with Jquery:

using a jquery plugin, from http://benalman.com/projects/jquery-replacetext-plugin/, I added that code to my template:

Code:
<h2 id="replace"><?php get_parent(); ?></h2>
    <script type="text/javascript">
            $(function() {
    $("#replace").replaceText( "-", " " );  
            });
        </script>

but maybe there is a solution without additional jquery plugin?

Cheers, Connie


output <?php get_parent(); ?> without hyphen in template - mvlcek - 2011-11-05

Just PHP:
Code:
<h2 id="replace"><?php echo str_replace('-',' ',get_parent(false)); ?></h2



output <?php get_parent(); ?> without hyphen in template - Connie - 2011-11-05

yes, that is a better solution, so I don't need an additional Jquery script

but: this was my first start with Jquery, not only integrating scripts, but using it for my own purpose, so I learned!

I will include the php, thank you!

I described this in our tipps-and-tricks-section at get-simple.de:

http://www.get-simple.de/gs-tipps-tricks/untermenue-mit-hauptpunkt-als-ueberschrift-aber-ohne-bindestriche/


output <?php get_parent(); ?> without hyphen in template - igestalten - 2012-03-24

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)


output <?php get_parent(); ?> without hyphen in template - Carlos - 2012-03-24

Using GS 3.1's new getPageField function:
Code:
<?php get_parent(0)!='' ? getPageField(get_parent(0),'title') : get_page_title();?>
displays parent title or current page title.


RE: output <?php get_parent(); ?> without hyphen in template - bigthanks - 2017-04-17

(2012-03-24, 03:52:05)Carlos Wrote: Using GS 3.1's new getPageField function:
Code:
<?php get_parent(0)!='' ? getPageField(get_parent(0),'title') : get_page_title();?>
displays parent title or current page title.

Let's say, on the main navigation I want to create a menu:
-Tutorial
-- GetSimple CMS
-- Wordpress

In the sidebar, I want create a child menu block:
GetSimple CMS : (title header)
-- Plugins (link)
--- How To Install Plugins (link)

Question: how to make the title child menu remain at "GetSimple CMS" even if a user is accessing the "How to Install Plugins"?
Please help and sorry for my english Smile