0

I have a plugin on my WordPress site that lists the most visited pages. I recently realized that it was displaying certain pages that I don't want to display. I also want to be able to disable pages of a certain category.

I found this line of code for the actual display of the widget:

public static function list_items( $post, $defaults ) {
        setup_postdata( $post );
        $post_id                = get_the_ID();
        $title                  = get_the_title() ? get_the_title() : $post_id;
        $post_class         = implode(get_post_class());
        $permalink          = get_permalink();
        $pre_thumbnail  = (has_post_thumbnail() && $defaults['thumbnail'] == 'before_title') ? get_the_post_thumbnail(get_the_ID(), $thumbnail_size) : '';
        $post_thumbnail = (has_post_thumbnail() && $defaults['thumbnail'] == 'after_title') ? get_the_post_thumbnail(get_the_ID(), $thumbnail_size) : '';
        $item                       = '
            <li class="' . $post_class . '">
                <a href="' . $permalink . '" title="' . $title . '">
                    ' . $pre_thumbnail . $title . $post_thumbnail . '
                </a>
            </li>
        ';
        $item                       = apply_filters('wp_most_popular_list_item_single', $item, $post_id, $title, $post_class, $permalink);
        echo $item;
    }

While this works, when it displays the classes, they are not spaced properly, so a page that should display: class="post-20 pagetype-page status-publish hentry category-member tag-member" is instead displaying class="post-20pagetype-pagestatus-publishhentrycategory-membertag-member".

Because of this, I cannot target the class category-member using CSS, or any other classes for that matter. How can I fix this?

I've tried removing the implode() from the $post_class array, but that has done nothing. I ave also tried simply using post_class() and get_post_class() to no avail.

0

An empty string is used for the glue parameter of implode(). get_post_class() will return an array, and you want to separate the array values with a space, so use this:

$post_class = implode( ' ', get_post_class() );

This appears to be a bug in the WP Most Popular plugin. I submitted an issue to the wordpress.org forums here. Hopefully the author will fix the bug, otherwise the fix posted above will be overwritten if the plugin is updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.