• Hi all,

    Was wondering if any code gurus out there could help me tweak a bit of script I have been using. It is a script I include in my footer as a way to show “popular posts”.

    My problem is that it displays results with the ‘ugly’ guid links. The p= kind. I would like it to return and display links using my permalinks.

    Any thoughts?

    Here is the code:

    <?php
    	$sql='SELECT post_title, comment_count, guid
    		FROM wp_posts WHERE post_status = "publish"
    		ORDER BY comment_count DESC
    		LIMIT 6;';
    	$results = $wpdb->get_results($sql);
    
    	foreach ($results as $r) {
    		echo '<li><a href="' . $r->guid . '" title="' . $r->post_title . '"> ' . $r->post_title .
    			' (' . $r->comment_count . ')</a></li>';
    	}
    ?>

Viewing 1 replies (of 1 total)
  • Thread Starter holdstrong

    (@holdstrong)

    Was able to answer my own question. Hope this helps someone else:

    <?php query_posts('orderby=comment_count&showposts=6');
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
          <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?> (<?php comments_number('0','1','%'); ?>)</a></li>
          <?php endwhile; ?>
          <?php else : ?>
          <li>Sorry, no posts were found.</li>
       <?php endif; ?>

Viewing 1 replies (of 1 total)

The topic ‘“Popular Posts” script that returns permalinks’ is closed to new replies.