WordPress.org

Ready to get started?Download WordPress

Forums

Show "Top postings" rank number (3 posts)

  1. lzz09
    Member
    Posted 4 years ago #

    I'm in the process of creating a WordPress theme and I just stumbled upon something I need help for.

    I want to show "top postings" in the sidebar, I've coded it already, see screenshot. I got the top postings code snippet from internet and I tweaked it to fit my theme design.
    The ranking of the posts are in order of comment count, which will be retrieved from the database, see the code:

    <?php $popular_posts = $wpdb->get_results("SELECT id, post_title FROM {$wpdb->prefix}posts ORDER BY comment_count DESC LIMIT 0,3"); foreach($popular_posts as $post) { ?>
         <div class="span-1"><span class="rank"><?php print $post->id; ?></span></div>
         <div class="span-5 last"><?php print "<a href='". get_permalink($post->id) ."'>".$post->post_title."</a><br/><br/>\n"; ?></div>
     <?php } ?>

    However, the code snippet didn't include the code to show the rank number. Temporarily I used the post id (see the code above), at the moment the posts with the ID's 1,2,3 are also ranked first, second and third respectively. (See screenshot)

    So does anyone know how to show the rank number? I know it's possible with <ol>...</ol>, but I don't want lists as it's not possible to style the ordered list number with css (this way I created with class="rank" a star badge background).

  2. lzz09
    Member
    Posted 4 years ago #

    I'm not in a big hurry, but I would love to hear some ideas...

  3. dajin
    Member
    Posted 3 years ago #

    Hello, Do you find it I need too...
    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic