Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/294430177860141057

highlighting Highlighting current item of custom post types' sub pages, listed by wp_list_pages

theThe below code is for listing the custom post types itself and its childschildren in the sidebar. theThe code works great but does not highlight the sub pages.

on the functions.phpIn functions.php:

if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page's id if there is no parent.
* 
* @uses object $post
* @return int 
*/
function get_post_top_ancestor_id(){
global $post;

if($post->post_parent){
    $ancestors = array_reverse(get_post_ancestors($post->ID));
    return $ancestors[0];
}

return $post->ID;
}}

and adding this code to the sidebar:

<ul>
<?php
$getid=get_post_top_ancestor_id(); 
#echo $getid;
global $post;
$post=get_post($getid);
setup_postdata($post);
?>
<?php
if (is_single($post->ID)) {$pg_li .="current_page_item";}
else {
$pg_li .="page_item";}
?>
<h3><?php the_title();?></h3>
<p></p>
<li class="<?php echo $pg_li; ?>">
<a href="<?php the_permalink(); ?>">BIOGRAPHY</a>
</li>
<li class="<?php echo $pg_li; ?>">
<?php
$args=array(
'post_type'=>'artists',
'child_of'=>$getid ,
'sort_column'=>'menu_order',
'hierarchical' => 1,
'title_li'=>__('')
);
wp_list_pages( $args );
wp_reset_query();
?></li>
</ul>

iI am not familiar with phpPHP, and a friend helped me to write this code. soSo what am iI missing to highlight the current sub menu of that custom post type??

thanks for helping.

highlighting current item of custom post types' sub pages, listed by wp_list_pages

the below code is for listing the custom post types itself and its childs in the sidebar. the code works great but does not highlight the sub pages.

on the functions.php:

if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page's id if there is no parent.
* 
* @uses object $post
* @return int 
*/
function get_post_top_ancestor_id(){
global $post;

if($post->post_parent){
    $ancestors = array_reverse(get_post_ancestors($post->ID));
    return $ancestors[0];
}

return $post->ID;
}}

and adding this code to the sidebar:

<ul>
<?php
$getid=get_post_top_ancestor_id(); 
#echo $getid;
global $post;
$post=get_post($getid);
setup_postdata($post);
?>
<?php
if (is_single($post->ID)) {$pg_li .="current_page_item";}
else {
$pg_li .="page_item";}
?>
<h3><?php the_title();?></h3>
<p></p>
<li class="<?php echo $pg_li; ?>">
<a href="<?php the_permalink(); ?>">BIOGRAPHY</a>
</li>
<li class="<?php echo $pg_li; ?>">
<?php
$args=array(
'post_type'=>'artists',
'child_of'=>$getid ,
'sort_column'=>'menu_order',
'hierarchical' => 1,
'title_li'=>__('')
);
wp_list_pages( $args );
wp_reset_query();
?></li>
</ul>

i am not familiar with php, and a friend helped me to write this code. so what am i missing to highlight the current sub menu of that custom post type??

thanks for helping.

Highlighting current item of custom post types' sub pages, listed by wp_list_pages

The below code is for listing the custom post types itself and its children in the sidebar. The code works great but does not highlight the sub pages.

In functions.php:

if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page's id if there is no parent.
* 
* @uses object $post
* @return int 
*/
function get_post_top_ancestor_id(){
global $post;

if($post->post_parent){
    $ancestors = array_reverse(get_post_ancestors($post->ID));
    return $ancestors[0];
}

return $post->ID;
}}

and adding this code to the sidebar:

<ul>
<?php
$getid=get_post_top_ancestor_id(); 
#echo $getid;
global $post;
$post=get_post($getid);
setup_postdata($post);
?>
<?php
if (is_single($post->ID)) {$pg_li .="current_page_item";}
else {
$pg_li .="page_item";}
?>
<h3><?php the_title();?></h3>
<p></p>
<li class="<?php echo $pg_li; ?>">
<a href="<?php the_permalink(); ?>">BIOGRAPHY</a>
</li>
<li class="<?php echo $pg_li; ?>">
<?php
$args=array(
'post_type'=>'artists',
'child_of'=>$getid ,
'sort_column'=>'menu_order',
'hierarchical' => 1,
'title_li'=>__('')
);
wp_list_pages( $args );
wp_reset_query();
?></li>
</ul>

I am not familiar with PHP, and a friend helped me to write this code. So what am I missing to highlight the current sub menu of that custom post type?

Source Link
sez
  • 41
  • 1

highlighting current item of custom post types' sub pages, listed by wp_list_pages

the below code is for listing the custom post types itself and its childs in the sidebar. the code works great but does not highlight the sub pages.

on the functions.php:

if(!function_exists('get_post_top_ancestor_id')){
/**
* Gets the id of the topmost ancestor of the current page. Returns the current
* page's id if there is no parent.
* 
* @uses object $post
* @return int 
*/
function get_post_top_ancestor_id(){
global $post;

if($post->post_parent){
    $ancestors = array_reverse(get_post_ancestors($post->ID));
    return $ancestors[0];
}

return $post->ID;
}}

and adding this code to the sidebar:

<ul>
<?php
$getid=get_post_top_ancestor_id(); 
#echo $getid;
global $post;
$post=get_post($getid);
setup_postdata($post);
?>
<?php
if (is_single($post->ID)) {$pg_li .="current_page_item";}
else {
$pg_li .="page_item";}
?>
<h3><?php the_title();?></h3>
<p></p>
<li class="<?php echo $pg_li; ?>">
<a href="<?php the_permalink(); ?>">BIOGRAPHY</a>
</li>
<li class="<?php echo $pg_li; ?>">
<?php
$args=array(
'post_type'=>'artists',
'child_of'=>$getid ,
'sort_column'=>'menu_order',
'hierarchical' => 1,
'title_li'=>__('')
);
wp_list_pages( $args );
wp_reset_query();
?></li>
</ul>

i am not familiar with php, and a friend helped me to write this code. so what am i missing to highlight the current sub menu of that custom post type??

thanks for helping.