Solved

create linked parent page title

Posted on 2010-09-22
12
340 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now