Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output <?php get_parent(); ?> without hyphen in template
#1
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?
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#2
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
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#3
Just PHP:
Code:
<h2 id="replace"><?php echo str_replace('-',' ',get_parent(false)); ?></h2
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#4
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/
|--
Die deutsche GetSimple-Webseite: http://www.Get-Simple.de = the german Get-Simple-Website!
Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#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
#6
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.
Reply
#7
(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
Reply




Users browsing this thread: 1 Guest(s)
Free HDTV Channels Residential Solar Panels