WordPress.org

Ready to get started?Download WordPress

Forums

Ambrosite Post Formats Widget
active item css selector (7 posts)

  1. deadelvis
    Member
    Posted 2 years ago #

    Any chance you could add a class/selector to the item that is clicked/currently selected?

    This would allow styling to show the active item in the widget... and would make this already great widget so much better! :)

    Cheers,

    http://wordpress.org/extend/plugins/ambrosite-post-formats-widget/

  2. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    It may be possible. I normally update my plugins after a new version of WordPress is released. WP 3.3 is coming out at the end of November; I will see about adding the requested feature at that time.

  3. deadelvis
    Member
    Posted 2 years ago #

    Thanks! Looking fwd to it!

  4. deadelvis
    Member
    Posted 2 years ago #

    Couldn't wait... so here's how I did it:

    For the LIST... replace:

    echo '<li class="post-format-item"><a title="' . str_replace('%format', $string, $tooltip) . '" href="' . get_post_format_link($slug) . '">' . $string . '</a>' . $count . $format_id . '</li>';

    with:

    $class = '';
    if(is_tax('post_format') && get_post_format()==str_replace('post-format-', '', $post_format->slug)){
    	$class = ' current_format_item';
    }
    echo '<li class="post-format-item'.$class.'"><a title="' . str_replace('%format', $string, $tooltip) . '" href="' . get_post_format_link($slug) . '">' . $string . '</a>' . $count . $format_id . '</li>';

    For the DROPDOWN... replace:

    echo '<option class="level-0" value="' . $slug . '">' . $string . $count . $format_id . '</option>';

    with:

    $selected = '';
    if(is_tax('post_format') && get_post_format()==str_replace('post-format-', '', $post_format->slug)){
    	$selected = 'selected';
    }
    echo '<option '.$selected.' class="level-0" value="' . $slug . '">' . $string . $count . $format_id . '</option>';

    Also... too bad that for links the DROPDOWN uses - http://name.tld/?post_format=image - and LIST uses - http://name.tld/archives/type/image - (or whatever other permalink customizations is defined). Consistency would be nice too, but didn't bother fixing.

    Let me know if you can consider implementing and releasing updated version.
    Thx

  5. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    deadelvis,

    Thanks for sharing your code. I am patiently awaiting the release of WP 3.3 (which it now appears will be delayed by a few weeks), but as soon as it comes out I will look to incorporating your changes into the plugin.

  6. deadelvis
    Member
    Posted 2 years ago #

    FIY...
    Just found there is a much easier and cleaner way to do the post formats listing:

    $args=$args = array(
    	'taxonomy'     => 'post_format',
    	'orderby'      => 'name',
    	'show_count'   => 1,
    	'hierarchical' => 0,
    	'title_li'     => ''
    );
    echo wp_list_categories( $args );

    Also... found a nasty bug with the counting of total posts. Both your code and mine will show incorrect counts, that include draft/pending/trashed posts. Seems to be a know issue with WP:

    http://wordpress.org/support/topic/custom-taxonomy-post-count-incorrect?replies=11
    http://wordpress.stackexchange.com/questions/28966/wp-list-categories-show-count-includes-publisheddraft-posts-with-custom-taxonom

    Keeping counts hidden for now. Hope a fix comes soon.

    Regards

  7. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    I just released an updated version of the plugin. I added the code for the active item css/selector more or less as given in this thread (thank you deadelvis). I also fixed the inconsistency in the link formats -- both the list and the dropdown now use permalinks instead of query strings, assuming permalinks are enabled.

    As far as the post counts being off: I am pulling that value directly from the "count" column in the wp_term_taxonomy table. Reading through the various Trac tickets that have been created for this problem, it looks like the bug is deep in the WordPress core. I really don't want to get involved in trying to fix that particular bug, since the core devs don't seem to be concerned about it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic