Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

create linked parent page title

Posted on 2010-09-22
12
Medium Priority
?
349 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 500 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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