Forums

how to highlight current post? (11 posts)

  1. smoo
    Member
    Posted 1 year ago #

    Hi,
    is there a way to highlight the current post item in the navigation, in the same way it's possible to highlight the current page?

    I am using mostly pages for my site, but have a 'news' section which is the blog, and am using get_archives() to list the posts even on single.php, but would like to show which post is the current one.

    I've found articles which show how to highlight the current archive, but not an actual post.

    It doesn't seem such an odd requirement, but I can't find anything anywhere, -am I asking in the wrong way?

    Thank you for any help
    -sam

  2. MichaelH
    moderator
    Posted 1 year ago #

  3. smoo
    Member
    Posted 1 year ago #

    Thank you for replying.

    However, I only need to highlight the current post, like current_page_item does for wp pages.
    Is there any other way of identifying the current post?
    -sam

  4. bacollier
    Member
    Posted 11 months ago #

    smoo - did you ever find an answer to this? I'm also wanting to achieve this without manually doing in my css code for each link

  5. smoo
    Member
    Posted 10 months ago #

    Hi bacollier,
    and no.. I didn't ever find a solution.
    I imagine something could be done with the source code that says:
    "if this url is the same as the current page url,
    then
    apply x class to the anchor tag"

    but I'm not savvy enough to hack the php.
    I guess it would also interfere with future wordpress updates if you did, so probably not a good idea unless you know what you're doing..

    How hard can it be tho?!
    -smoo

  6. PaulWarren
    Member
    Posted 4 months ago #

    Hi Guys,
    This is driving me nuts as well. Did anyone ever come up with a solution? I found this:

    http://www.kevinleary.net/highlight-current-wordpress-post-on-the-sidebar/

    Which seemed like a good solution but I couldn't make it work. Is there nothing like current_POST_item?

    The site I am working on is visable here http://altuit.on-rev.com/cig-test/category/cignews/

    The way the blog part of the site works is visible on under the left 4 menu items. Each section is pulling from a post category with

    <?php query_posts('cat=1&showposts=3'); ?>

    I was able to use conditionals to build a dynamic sidebar and highlight the active page items and the archive pages when clicked. The client really wants to highlight the active blog post. Is there any way? Is anyone having any luck with the jQuery method on Kevin Leary's site?

  7. Xamataca
    Member
    Posted 4 months ago #

    Post are identified by a unique id. In your theme templates you can see the bit of code that outputs that:
    id="post-<?php the_ID(); ?>
    It shouldn't be hard to append a specific class or change css on the fly using Javascript or PHP depending on id.

  8. PaulWarren
    Member
    Posted 4 months ago #

    Xamataca, Can you offer the php to do this? It seems like it would really help a few others in the same bind! The ideal solution for me would be something that uses query_posts so that we can limit the posts to one category.

  9. eggnog
    Member
    Posted 4 months ago #

    I've also been digging around for a solution to this problem. Found tons of tutorials on how to do this with a page menu you generate yourself, but nothing helpful for setting a class for current posts. Any help is appreciated.

  10. eggnog
    Member
    Posted 4 months ago #

  11. smoo
    Member
    Posted 3 months ago #

    Wow, thanks so much!
    Have just had to let it go with previous sites, but I'll give that a go for the next one..

Topic Closed

This topic has been closed to new replies.

About this Topic