Posts: 2,928
Threads: 195
Joined: Feb 2011
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?
Posts: 2,928
Threads: 195
Joined: Feb 2011
I found a solution with Jquery:
using a jquery plugin, from
http://benalman.com/projects/jquery-repl...t-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
Posts: 2,094
Threads: 54
Joined: Jan 2011
Just PHP:
Code:
<h2 id="replace"><?php echo str_replace('-',' ',get_parent(false)); ?></h2
Posts: 2,928
Threads: 195
Joined: Feb 2011
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...destriche/
Posts: 6
Threads: 1
Joined: Mar 2012
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)
Posts: 3,491
Threads: 106
Joined: Mar 2010
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.
Posts: 18
Threads: 3
Joined: Oct 2015
(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