• Resolved Robin

    (@cinghaman)


    Hi,

    All works perfectly the only thing I want to control is the number of categories being shown when I use
    {category}

    I have 3-5 category assigned to every post I Just want in the widget to show 1 category at the moment I am hiding them with CSS but would like a way to just do it through plugin itself

    {thumb}
    {title}
    {category}

    Output
    Image
    Title of the post
    Cat, cat2, cat3

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @cinghaman,

    Next release will include a filter hook that you can use for this. No ETA though so feel free to add this change manually to the plugin if this is something you need right away.

    Thread Starter Robin

    (@cinghaman)

    @hcabrera Thanks yup will use it at the moment, thanks

    Thread Starter Robin

    (@cinghaman)

    Hi @hcabrera
    I tried adding this filter let me know if it is wrong as i don’t see any change?

    /*
    * filter for most popular
    */
    $terms = get_terms(
    $taxonomy,
    array(
    ‘number’ => 1,
    )
    );
    apply_filters( ‘wpp_post_terms’, $terms );

    Plugin Author Hector Cabrera

    (@hcabrera)

    Assuming you already modified the src/Output.php file as shown on my previous comment (it sounds like you didn’t), then no I don’t see anything wrong with your code – except for the fact that it won’t work as you expect it.

    The get_terms() function returns all of the terms under a given taxonomy (eg. all of the terms that are Categories) not just the ones related to each post (read the documentation for more details.)

    Instead of that, 1) make sure you add the modification to src/Output.php exactly the same way as seen on the link I shared above, then 2) add this to your theme’s functions.php file:

    /**
     * Have WordPress Popular Posts display only one category.
     */
    add_filter('wpp_post_terms', function($terms){
        return array_slice($terms, 0, 1);
    });
    Thread Starter Robin

    (@cinghaman)

    Thanks gotcha

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Only 1 Category’ is closed to new replies.