• Resolved dillydally2095

    (@dillydally2095)


    Hi, I have a list of pages on my homepage theme that can be added to via cms, I want to highlight the current page I am on when clicked, but cant keep adding the ‘is page’ handle in the front of each link, as I will be adding pages if that makes sense? Is there any other ways to highlight the current page?

    Thanks

    A

Viewing 9 replies - 1 through 9 (of 9 total)
  • TimDesain

    (@timdesain)

    that can be added to via cms?

    do you mean wp_nav_menu?

    Thread Starter dillydally2095

    (@dillydally2095)

    No, the pages get added to the list by calling a list of posts from a specific category:

    <?php query_posts('cat=11&showposts=20'); ?>
    <ul>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(''); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    this seems to work in displaying the different posts, however once new posts are added and then added to the list I want the colour of the current post to be a different colour.

    Thanks

    A

    TimDesain

    (@timdesain)

    put this code inside post looping
    <?php $tdID = get_the_ID(); ?>
    after
    <?php while ( have_posts() ) : the_post(); ?>

    replace your code with

    <?php global $tdID; ?>
    <?php query_posts(); ?>
    <ul id="postlist">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a <?php echo ($tdID==get_the_ID()?'class="current"':'');?> href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(''); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    put css in style.css
    #postlist .current{color:#fff;background:#f00;}

    Thread Starter dillydally2095

    (@dillydally2095)

    Thanks for getting back to me…I cant seem to get it working!! Do I need to literally replace the code I pasted on this forum with this?

    <?php global $tdID; ?>
    <?php query_posts(); ?>
    <ul id="postlist">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a <?php echo ($tdID==get_the_ID()?'class="current"':'');?> href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(''); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    where does this feature? so i can point to the categories?
    <?php query_posts('cat=11&showposts=20'); ?>

    Thanks

    TimDesain

    (@timdesain)

    i’m sorry.
    replace
    <?php query_posts(); ?>
    with
    <?php query_posts('cat=11&posts_per_page=20'); ?>

    make sure this code inside post looping first
    <?php $tdID = get_the_ID(); ?>
    after
    <?php while ( have_posts() ) : the_post(); ?>

    Thread Starter dillydally2095

    (@dillydally2095)

    Hi TIm, almost there, its adding the current id to the links and styling…But to all of them!! This is the code I have at the moment…

    <?php global $tdID; ?>
    <?php query_posts('cat=11&showposts=20'); ?>
    <ul id="postlist">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php $tdID = get_the_ID(); ?>
    <li>
    <a <?php echo ($tdID==get_the_ID()?'class="current"':'');?> href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(''); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    TimDesain

    (@timdesain)

    sorry for my english.

    1. open single.php or *-single.php or single-*.php
    put this code
    <?php $tdID = get_the_ID(); ?>
    after
    <?php while ( have_posts() ) : the_post(); ?>

    2. list posts by category

    <?php global $tdID; ?>
    <?php query_posts('cat=11&posts_per_page=20'); ?>
    <ul id="postlist">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a <?php echo ($tdID==get_the_ID()?'class="current"':'');?> href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(''); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    3. style
    put css in style.css
    #postlist .current{color:#fff;background:#f00;}

    Thread Starter dillydally2095

    (@dillydally2095)

    Cheers Tim, got there in the end! Much appreciated!!

    TimDesain

    (@timdesain)

    nice work.
    ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Highlighting current page’ is closed to new replies.