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

  1. deadelvis
    Posted 4 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! :)



  2. ambrosite
    Plugin Author

    Posted 4 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
    Posted 4 years ago #

    Thanks! Looking fwd to it!

  4. deadelvis
    Posted 4 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>';


    $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>';


    $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.

  5. ambrosite
    Plugin Author

    Posted 4 years ago #


    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
    Posted 4 years ago #

    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:


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


  7. ambrosite
    Plugin Author

    Posted 4 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

  • Ambrosite Post Formats Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic