shouldn’t there be an echo in the code?
btw: it would add the class ‘.current_page’ to all pages in the loop.
Maybe, I am newer to php and WP. I can typically figure these things out slowly but surely but this one has been giving me fits. I assume by echo you mean that somewhere in there I should say echo “if its the current page put class=”current_page”.
At the end of the day I only want the .current_page on the current_page, and I dont think I can use wp_list_pages for this as I am grabbing different pieces of content from the page.
any more help is greatly appreciated.
try:
<li <?php $class = ($current_id == $post->ID) ? ' class="current_page' : ''; echo $class; ?>>
Check if one of the query vars is set prior to the loop, then check against that value in the post loop.
Example:
<?php
// Store queried page name if available (should be available for pretty permalinks)
$_queried_page = ( get_query_var('pagename') ) ? get_query_var('pagename') : false;
// Store queried page id if available (fallback if pagename failed)
$_queried_page_id = ( get_query_var('page_id') ) ? get_query_var('page_id') : false;
query_posts( array(
'post_parent' => 6,
'post_type' => 'page'
) );
while (have_posts()) :
the_post();
// Check if the post name is the queried page
if( $_queried_page && ( $_queried_page == $post->post_name ) )
$append = ' class="current_page';
// If pagename not set, check id
elseif( $_queried_page_id && ( $_queried_page_id == $post->ID ) )
$append = ' class="current_page';
// Else not current
else
$append = '';
?>
<li<?php echo $append; ?>>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('align=left'); ?>
<span class="products_title"><?php the_title(); ?></span>
<span class="products_arrow"></span>
</a>
</li>
<?php
endwhile;
?>
Hope that helps…
Thanks so much for all this help. I will work to implement and see how it goes. Then I’ll report back… thanks
Mark that was exactly what I needed. Thank you for your help.