create linked parent page title

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

lauras2010Asked:
Who is Participating?
 
jrm213jrm213Connect With a Mentor Commented:

<?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
 
lauras2010Author Commented:
Thank you very much ... jrm213jrm213 ... !
0
 
jrm213jrm213Commented:
You're welcome, glad I could help.  
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
lauras2010Author Commented:
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
 
jrm213jrm213Commented:
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
 
jrm213jrm213Commented:
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
 
lauras2010Author Commented:
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
 
jrm213jrm213Commented:
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
 
jrm213jrm213Commented:
shoot you would also need

to change $parent_title to the_title()
0
 
lauras2010Author Commented:
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
 
lauras2010Author Commented:
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
 
lauras2010Author Commented:
I'm going to open up a new question and assign more points. Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.