• Resolved rodrego

    (@rodrego)


    Hi,

    I’m designing a portfolio-website (http://gabirocha.com) which has a collapsible menu showing posts inside categories,

    I created the menus using the get_posts function like follows:

    <?php
                                $args = array( 'category' => 3, 'numberposts' => 100, 'order' => 'ASC' );
                                $cat3 = get_posts( $args );
                                foreach( $cat3 as $post ) : ?>
    
    <li>
                                        <a>">
                                            <?php the_title(); ?>
                                        </a>
                                    </li>
                            <?php endforeach; ?>

    Now I want to highlight the current post, but I couldn’t find any documentation on doing this besides using tags like wp_nav_menu

    Is it possible to do it?

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • one possibility: get the current $post id before your code; save it to a variable; compare it with the id in your loop – if the same, output a css class:

    rough example:

    <?php global $post; //possibly not needed?//
    $current_id = $post->ID; ?>
    //start of your code//
    //somewhere in your code, for instance in the <li> tag//
    <li<?php if( $current_id == $post->ID ) echo ' class="current"'; ?>>
    //rest of your code//
    Thread Starter rodrego

    (@rodrego)

    Thank you alchymyth, it worked great!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Highlight Current Page in WordPress’ is closed to new replies.