Solved

create linked parent page title

Posted on 2010-09-22
12
347 Views
Last Modified: 2012-05-10
I have a WordPress CMS site (not for blogging) with a left sidebar that is designed to show only the links to pages in a current section of the site.For example, if I'm in the About Us section of the website, then the left sidebar should show this:

About Us
Message from the President
History
Mission Statement

Right now I can display the title of the section and the links to the pages, but the title itself is not linked. Code is attached ...

Can someone help me figure out how to link the title of the section?

Thanks,
Laura S.

<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
echo "<ul>";
echo '<li class = "page_item parent" >';
echo get_the_title($post->post_parent);
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
} ?>

Open in new window

0
Comment
Question by:lauras2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 125 total points
ID: 33743613

<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$parent_title = get_the_title($post->post_parent);
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>'); } 
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
} ?>

Open in new window

0
 

Author Closing Comment

by:lauras2010
ID: 33744532
Thank you very much ... jrm213jrm213 ... !
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33745261
You're welcome, glad I could help.  
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:lauras2010
ID: 33752614
Actually I just realized that this isn't working for sections that only have one page -- i.e., if my About Us section was only the About Us page (and I do have other sections that are just one page) -- then right now there is nothing shows up as a linked section title.

Could you help me with this one additional piece? I will add more points if I can figure out how to do it.
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33753000
that is because those pages with no child elements do not have a $post->post_parent so you need code in your "else" portion of the "if" statement to handle that situation.
<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$parent_title = get_the_title($post->post_parent);
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>'); } 
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
cho "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>'); } 
echo "</li></ul>";
} ?>

Open in new window

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33753006
oh, don't worry about more points. I don't think you can add more anyway and I don't think this warrants a new question.
0
 

Author Comment

by:lauras2010
ID: 33755372
Thanks for that but it didn't work -- it's still not displaying the linked section title (it's not displaying anything at all). I did find a couple of small typos in your code so I fixed them, so this is what I have (below). Very sorry for the trouble ... tell me if you want me to open up a new question for this.
<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$parent_title = get_the_title($post->post_parent);
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>');
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>');
echo "</li></ul>";
} ?>

Open in new window

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33755547
ah sorry

change line 15 (I believe to use $post->id)

echo ('<a href=\"' . get_permalink($post->id) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>');
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33755562
shoot you would also need

to change $parent_title to the_title()
0
 

Author Comment

by:lauras2010
ID: 33755739
That didn't work either :((( I tried two different things (both listed in the code block below)


<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$parent_title = get_the_title($post->post_parent);
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>');
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->id) . '\" title=\"' . the_title() . '\">' . the_title() . '</a>');echo "</li></ul>";
} ?>





<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$parent_title = get_the_title($post->post_parent);
$parent = get_the_title($post->id);
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->post_parent) . '\" title=\"' . $parent_title . '\">' . $parent_title . '</a>');
echo "</li>";
if ($children) {
echo $children;
echo "</ul>";
} else {
echo "<ul>";
echo '<li class = "page_item parent" >';
echo ('<a href=\"' . get_permalink($post->id) . '\" title=\"' . $parent . '\">' . $parent . '</a>');echo "</li></ul>";
} ?>

Open in new window

0
 

Author Comment

by:lauras2010
ID: 33755763
Actually I think it's the } else { that isn't working (line 12). If I create a new line 13 and put echo "test"; in that line, even that doesn't work.
0
 

Author Comment

by:lauras2010
ID: 33760830
I'm going to open up a new question and assign more points. Thanks again!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question