Advertisement
bradtrivers

WordPress.com Popular Posts example

Apr 10th, 2012
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.35 KB | None | 0 0
  1. // changed epanel/widget-tabbed.php file in ElegantThemes.com DelicateNews theme
  2. //to use Jetpack stats via the WordPress.com Popular Posts plugin to retrieve popular posts (instead of comments)
  3. <ul>
  4.     <?php if (function_exists('WPPP_show_popular_posts')) { //Relies on WordPress.com Popular Posts plugin
  5.           WPPP_show_popular_posts( "title=&list_tag=none&number=".$popularPostsNumber."&thumbnail_size=59&format=<li><a href='%post_permalink%' title='%post_title_attribute%' class='clearfix'><span class='box'><span class='overlay'></span>%post_thumbnail%</span><span class='title'>%post_title% (%post_views% views)</span></a></li>" );  
  6.           /* Optionally you can add some parameters to the function, in this format:
  7.           * name=value&name=value etc.
  8.           *
  9.           * Possible names are:
  10.           * - title (title of the widget, you can add tags (e.g. <h3>Popular Posts</h3>) default: Popular Posts)
  11.           * - number (number of links shown, default: 5)
  12.           * - days (length of the time frame of the stats, default 0, i.e. infinite)
  13.           * - show (can be: both, posts, pages, default both)
  14.           * - format (the format of the links shown, default: <a href='%post_permalink%' title='%post_title%'>%post_title%</a>)
  15.           * - time_format (the format used with %post_time%, see http://codex.wordpress.org/Formatting_Date_and_Time)
  16.           * - thumbnail_size (the width/height in pixels of the post's thumbnail image)
  17.           * - excerpt_length (the length of the excerpt, if %post_excerpt% is used in the format)
  18.           * - title_length (the length of the title links, default 0, i.e. unlimited)
  19.           * - exclude (the list of post/page IDs to exclude, separated by commas)
  20.           * - exclude_author (the list of authors IDs to exclude, separated by commas)
  21.           * - cutoff (don't show posts/pages with a view count under this number, default 0, i.e. unlimited)
  22.           * - list_tag (can be: ul, ol, none, default ul)
  23.           * - category (the ID of the category, see FAQ for info. Default 0, i.e. all categories)
  24.           * - cachename (it is used to enable the cache. Please see the FAQ)
  25.           * - cache_only_when_visitor (if enabled, it doesn't serve a cached version of the popular posts to the users logged in, default 0)
  26.           * - magic_number (set it to a number greater than 1 if you see less links than expected)
  27.           *
  28.           * Example: if you want to show the widget without any title, the 3 most viewed
  29.           * articles, in the last week, and in this format: My Article (123 views)
  30.           * you will use this:
  31.           * WPPP_show_popular_posts( "title=&number=3&days=7&format=<a href='%post_permalink%' title='%post_title_attribute%'>%post_title% (%post_views% views)</a>" );
  32.           *
  33.           * You don't have to fill every field, you can insert only the values you
  34.           * want to change from default values.
  35.           *
  36.           * You can use these special markers in the `format` value:
  37.           * %post_permalink% the link to the post
  38.           * %post_title% the title the post
  39.           * %post_title_attribute% the title of the post; use this in attributes, e.g. <a title='%post_title_attribute%'
  40.           * %post_views% number of views
  41.           * %post_thumbnail% the thumbnail image of the post.
  42.           * %post_excerpt% the first n characters of the content. Set n with excerpt_length.
  43.           * %post_category% the category of the post
  44.           * %post_comments% the number of comments a post has
  45.           * %post_time% the date/time of the post. You can set the format with time_format.
  46.           * %post_author% the author of the post.
  47.           */
  48.         } else { ?>
  49.              
  50.                 <?php global $wpdb;
  51.                     $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $popularPostsNumber");
  52.                     foreach ($result as $post) {
  53.                         #setup_postdata($post);
  54.                         $postid = $post->ID;
  55.                         $title = $post->post_title;
  56.                         $commentcount = $post->comment_count;
  57.                         if ($commentcount != 0) { ?>
  58.                             <?php query_posts("p=$postid"); ?>
  59.                             <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  60.                                 <?php get_template_part('includes/fromblog_post'); ?>
  61.                             <?php endwhile; endif; wp_reset_query(); ?>
  62.                         <?php };
  63.                     };?>
  64.   <?php } ?>
  65.             </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement