• Would it be possible to indicate what page you are in just like the function of wp_list_pages that inserts the current_page class? I am using a query posts to create like menu and I want my visitors to know where they are on the page. Below is my code in creating menu out of query post

    <?php rewind_posts(); ?>
                                <?php query_posts('category_name=front-desk&posts_per_page=7&offset=7&orderby=title&order=ASC'); ?>
                            	<?php while ( have_posts() ) : the_post(); ?>
    
                            		<?php the_title('<li><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></li>'); ?>
    
                            	<?php endwhile; ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • If you can save the ID of the current post as $current_id, then this should work:

    <?php rewind_posts(); ?>
    <?php query_posts('category_name=front-desk&posts_per_page=7&offset=7&orderby=title&order=ASC'); ?>
    <?php while ( have_posts() ) : the_post(); ?>
       <?php $class = ($current_id == $post->ID) ? ' class="current_page' : '';
       <?php the_title("<li$class><a href=\"" . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></li>'); ?>
    
    <?php endwhile; ?>
    Thread Starter louissoriano

    (@louissoriano)

    Thank you so much, will try this and will set this to resolved ??

    Thread Starter louissoriano

    (@louissoriano)

    I’m afraid the list is not coming out when the code is inserted, but will try to figure this out, thank you for this ??

    Did you assign a value to $current_id earlier in the code – while in the loop before the rewind_posts()?

    Thread Starter louissoriano

    (@louissoriano)

    No I didn’t. I think I would need help on that too. Sorry am new to wordpress ??

    Find the place in the loop ahead of this one where you have a call to the_post(). It may look something like this:

    if (have_posts()) : while (have_posts()) : the_post(); ?>

    If that line ends in ?>, change it to this:

    if (have_posts()) : while (have_posts()) : the_post();
       $current_id = $post->ID; ?>

    If that line does not end in ?>, do this instead:

    if (have_posts()) : while (have_posts()) : the_post();
       $current_id = $post->ID;
    Thread Starter louissoriano

    (@louissoriano)

    Thanks mate! Will try this!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Inserting current_page class out of query post’ is closed to new replies.