logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
WP Most Popular Posts Show Weekly

Hi,

I am using Wordpress Popular Posts.

I have modified the plugin heavily to make it work with my site.


Currently on the homepage of my site it shows the most recent posts by day, week and month

The problem is at the beginning of each new day there are no popular posts for the day for the first few hours, so it breaks my layout.

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



The plugin writer gave me this code below to display the week's popular posts in place of the day's popular posts if there was none for the day. The code just showed up blank.

if ( !is_array($mostpopular) || empty($mostpopular) ) {
$mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts RIGHT JOIN ".$table."cache ON $wpdb->posts.ID = ".$table."cache.id WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND ".$table."cache.day >= '".gmdate("Y-m-d")."' - INTERVAL 7 DAY AND ".$table.".pageviews > 0 $nopages $exclude GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");
}



If there are no popular posts for the day, I want the popular posts for the week to show up.

PM me if you want the full plugin code



ag123 | 01/03/12 at 1:46pm Edit
Tutorial: How to assign prize money


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/03/12
    1:49pm
    Arnav Joy says:

    please tell me what is the result of

    print_r($mostpopular);

    please paste the result here

    • 01/03/12 1:54pm

      Arnav Joy says:

      or you can use it as

      foreach ( $mostpopular as $mp)
      {
      ?>
      <a href="<?php echo $mp->guid;?>"><?php echo $mp->post_title;?></a>
      <?php } ?>

    • 01/03/12 1:54pm

      ag123 says:

      Array ( )


      that was all that came out when I put in

      print_r($mostpopular);

  • avatar
    Last edited:
    01/03/12
    2:04pm
    John Cotton says:

    Try this:


    if ( !is_array($mostpopular) || empty($mostpopular) ) {
    $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts RIGHT JOIN {$table}cache ON
    $wpdb->posts.ID = {$table}cache.id
    WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = ''
    AND {$table}cache.day >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
    AND {$table}pageviews > 0 $nopages $exclude
    GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . ");
    }

    • 01/03/12 4:34pm

      ag123 says:

      Hi,

      I got this error code when I used this code


      Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING



      Full plugin

    • 01/03/12 6:00pm

      John Cotton says:

      Looking at that plugin code, it seems you've cut and pasted with some odd CR/LFs.

      Try this:


      if ( !is_array($mostpopular) || empty($mostpopular) ) {
      $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts RIGHT JOIN {$table}cache ON $wpdb->posts.ID = {$table}cache.id WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND {$table}cache.day >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND {$table}pageviews > 0 $nopages $exclude GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] );
      }

This question has expired.





Current status of this question: Community pot



Please log in to add additional discourse to this page.





Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.