WordPress.org

Ready to get started?Download WordPress

Forums

WP Category Post List Widget
Highlight Active Post (3 posts)

  1. JWSchaeffer
    Member
    Posted 1 year ago #

    I want the active post to be highlighted within the WP Category Post List.

    How do I make this happen?

    http://wordpress.org/extend/plugins/wp-category-posts-list/

  2. flavigne
    Member
    Posted 1 year ago #

    I am wondering this too, I think it cannot be done right now. Still digging in the source code.

  3. pdboller
    Member
    Posted 1 year ago #

    I know this is an old post, but I was looking for this today and could not find a solution so I thought I'd post what I did. Please note: I am NOT a coder - it took me a while to tweak the code to get to this point, and it may be wrong, but it works for me so it may work for others too.

    Also, this probably removes some/all of the functionality of the widget options. I was working on a custom theme that the end user will not change, so this does not affect me.

    Use at your own risk!

    Here's what I did.

    In /plugins/wp-category-posts-list/includes/wp_cpl_output_gen.php look for /** Initiate the post list widget HTML. Replace:

    $default_class = ((true == $op['alternate_list_css'])? (($i%2 == 0)? 'wp-cpl wp-cpl-even' : 'wp-cpl wp-cpl-odd') : 'wp-cpl');

    With:

    $current_url_1 = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    if($current_url_1 == get_permalink($post->ID)) {
    $default_class = 'wp-cpl wp-cpl-current';
    } else {
    $default_class = ((true == $op['alternate_list_css'])? (($i%2 == 0)? 'wp-cpl wp-cpl-even' : 'wp-cpl wp-cpl-odd') : 'wp-cpl');
    }

    (I basically replace the automatically generated default class with a new current/active class IF the specific link is the current one/same as the current URL).

    After this, just add the class to your CSS file to give the current link a different style.

    If anyone has a better option/solution, I'm always happy to learn something new!
    (Edit: tried to fix some formatting issues for this post)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic