• Resolved staceyud

    (@staceyud)


    I’m currently using this to display a set of links of 10 posts in one of my categories:

    <ul>
    <?php
     $myposts = get_posts('numberposts=10&category=4');
     foreach($myposts as $post) :
     ?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    I want to be able to add a class to the li tag when the current page is active. For example, my list looks like this:

    page 1
    page 2
    page 3

    etc.

    if I’m ON page 2, I want to add a class=”current” to my li tag so I can bold or largen my ‘page 2’ text.

    I’ve tried to write my own if statement but I’m getting no where..

    I need something like

    if this page == catpageinlist echo class=”current” (you get the point)

    Any ideas?

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter staceyud

    (@staceyud)

    Solved!

    For anyone who wants to know, this is what I did:

    In the header template file, in the head tag, put this:

    <style type="text/css">
    li.postlink-<?php echo $post->ID; ?> a {
    font-weight: strong /*whatever you want*/ }
    </style>

    then on my sidebar.php where i call the links in one category I have this:

    <ul>
    <?php
     $myposts = get_posts('numberposts=10&category=4');
     foreach($myposts as $post) :
     ?>
    <li class="postlink-<?php echo $post->ID; ?>">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>

    Hooray!

Viewing 1 replies (of 1 total)
  • The topic ‘get_posts and current page’ is closed to new replies.