Loading...

Tagged: top RSS

  • The SourceBench 11:13 pm on November 27, 2009 Permalink | Reply
    Tags: tag, tag usage, top,   Posted in WordPress

    Display posts by the TAG usage. Most used tags and their posts go first 

    <?php
    /*
     * Display posts order by the frequency a tag is used.
     * Most used tags first with the posts in it.
     * Found at http://www.devlounge.net/code/wordpress-snippet-display-posts-by-tag-frequency
     */
      $noOfTags = 10;
      $noOfPosts = 4;
      $cloudRight = get_tags("orderby=count&order=DESC&number=$noOfTags");
      foreach((array)$cloudRight as $tagRight) : ?>
    	  <?php
    	  $postsRight = new WP_Query();
    	  $postsRight->query("tag={$tagRight->slug}&showposts=$noOfPosts");
    	  ?>
    	  <?php if ( $postsRight->have_posts() ) :? >
    		<dl class="xoxo">
    		  <dt><?php echo $tagRight->name ?></dt>
    		  <?php while ( $postsRight->have_posts() ) : $postsRight->the_post(); ?>
    		  <dd><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></dd>
    		  <?php endwhile;?>
    		</dl>
    	  <?php endif; ?>
      <?php
    	unset($postsRight);
      endforeach;
    ?>

     
  • The SourceBench 11:05 pm on November 27, 2009 Permalink | Reply
    Tags: comments, top,   Posted in WordPress

    A really simple way to show top posts determined by comment count 

    <?php
    // a simple way to get most popular posts by comment count, just throw it in your templatefile and alter t your needs
    $max = 10; // amount of posts to get
    ?>
    <ul>
    <?php
    $result = $wpdb->get_results( $wpdb->prepare( "SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0, %d", $max ) );
    foreach ($result as $post) :
    	setup_postdata($post);
    	$postid = $post->ID;
    	$title = $post->post_title;
    	$commentcount = $post->comment_count;
    	if ($commentcount != 0) :
    ?>
    		<li>
    			<a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"> <?php echo $title ?></a> (<?php echo $commentcount ?>)
    		</li>
    <?php
    	endif;
    endforeach;
    ?>
    </ul>

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel