WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
If mostpopular is empty, show yesterday's posts (6 posts)

  1. jaggreene
    Member
    Posted 2 years ago #

    Hi,

    Currently in the plugin, when there are no posts to show for the daily range.

    The following code is activated.

    if ( !is_array($mostpopular) || empty($mostpopular) ) {
    				$content .= "<p><a href=\"/videos\">".__('Looking for videos? Click here', 'wordpress-popular-posts')."</a></p>"."\n";
    			}

    I noticed it looked strange on my site, so I want to make if there is no content in a range, it will display the most popular posts from yesterday. How do I do that?

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Hi jaggreene,

    Currently, there's no way to achieve this. Earlier versions of WordPress Popular Posts had an undocumented "yesterday" option for the Time Range feature that allowed users to get the most popular posts from yesterday only. However, the daily option has been replaced with the last 24 hours so the yesterday option doesn't work anymore.

  3. jaggreene
    Member
    Posted 2 years ago #

    Hi Hector,

    Thanks for the answer.

    How do I change the above code then to show the most popular posts from the week (instead of yesterday) when $mostpopular is empty?

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Here's a modified copy of my plugin. I didn't test it, but it should do what you want.

    Be aware that this is a hack, and once WordPress Popular Posts is updated again all these changes will be lost. Modifications were made on the get_popular_posts function only, so you probably want to save a copy of that for future reference.

  5. jaggreene
    Member
    Posted 2 years ago #

    Hi,

    thanks for the code. $mostpopular just shows up blank instead of displaying the week's video posts.

    I think my best option now is to just have an html notice when $mostpopular is blank directing them to a search page.

    I had

    if ( !is_array($mostpopular) || empty($mostpopular) ) {
    				$content .= "<p><a href=\"/videos\">".__('Looking for videos? Click here', 'wordpress-popular-posts')."</a></p>"."\n";
    			}

    I also tried

    if ( !is_array($mostpopular) || empty($mostpopular) ) {
    				$mostpopular .= "<p><a href=\"/videos\">".__('Looking for videos? Click here', 'wordpress-popular-posts')."</a></p>"."\n";
    			}

    neither seemed to work

  6. jaggreene
    Member
    Posted 2 years ago #

    Hi,

    Any help on this would be appreciated

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic