Solved

create linked parent page title

Posted on 2010-09-22
12
345 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

856 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