Support » Themes and Templates » Highlight visible post in archive.php

  • Hello. Sorry having a bit of trouble with my dynamic highlight on my menu.

    In my archive.php I am showing the list of projects within the category and showing the most recent post.

    I am able to call up the visible posts ID and use it as $post_id

    The menu highlights the current single post using
    if ( is_single(“$post->ID”

    But I need a
    if ( **visiblepost**(“$post_id”)

    Anyone have any ideas? The code I am using is shown below.

    <li <?php
    //gets shown post ID
    global $wp_query;
    $post_id = $wp_query->post->ID;
    //highlights current post id. shown post in archive not working!!!!
    if ( is_single(“$post->ID”) || the_post(“$post_id”) ) { echo ‘ class=”current_page_item”‘; } ?>>
    “><?php the_title(); ?>

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

    (@amogle)

    I solved the issue using

    $post_id == $post->ID

    So the line is now

    if ( is_single(“$post->ID”) || $post_id == $post->ID ) ) { echo ‘ class=”current_page_item”‘; }

    works like a charm 🙂

    I realise that $post_id is confusing so I would recommend calling it $currentpostid instead.

Viewing 1 replies (of 1 total)
  • The topic ‘Highlight visible post in archive.php’ is closed to new replies.