Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:12:41+00:00 2026-05-24T18:12:41+00:00

Now i tried some other ways…. <?php /* Start popular Post */ ?> <li>

  • 0

Now i tried some other ways….

<?php /* Start popular Post */ ?>   
    <li>
        <h3>Popular Posts</h3>
        <ul class="bullets">
        <?php
          $args = array( 'numberposts' => 5 );
          $thumbnails = get_posts($args);
          foreach ($thumbnails as $thumbnail) {
            if ( has_post_thumbnail($thumbnail->ID)) {
              echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
              echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
              echo '</a>';
            }
          }
        ?>

        </ul>
    </li>
<?php /* End popular Post */ ?>

and its working but its only showing the most recent posts. unless most popular post 🙁

…..

having trouble with popular post…

<?php /* Start popular Post */ ?>   
    <li>
        <h3>Popular Posts</h3>
        <ul class="bullets">
        <?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 $pop) {
                    if ( has_post_thumbnail($pop->ID) ) {
        ?>
            <li>
        <?php   the_post_thumbnail(array(100,100)); ?>
            </li>
        <?php
                    }
                }
        ?>
        </ul>
    </li>
<?php /* End popular Post */ ?>

i am trying to grab 3 popular posts but when i am using the above code they are just showing me image of my recent post …

help me to figure out this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:12:41+00:00Added an answer on May 24, 2026 at 6:12 pm

    Try using get_the_post_thumbnail( $id, $size, $attr ) and pass in the Post ID. Also note that you should specify in your query post_type = 'post' to filter out non-posts.

    Documentation: http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

    —

    I’ve confirmed locally that the following works:

    // Query should select only posts, order by comment_count descending
    $p_posts_query = "SELECT ID, post_title 
                      FROM wp_posts 
                      WHERE post_type = 'post' 
                      ORDER BY comment_count DESC";
    
    // Load results of our query into variable $p_posts
    $p_posts = $wpdb->get_results($p_posts_query); 
    
    // Cycle through each result
    foreach ( $popular_posts as $pop ) {
    
        // If there is a thumbnail associated with this post
        if ( has_post_thumbnail( $pop->ID ) ) {
    
          // Show the thumbnail for this post
          echo get_the_post_thumbnail( $pop->ID );
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following DateTime start = Convert.ToDateTime(TextBox1.Text); DateTime end = Convert.ToDateTime(TextBox2.Text); if (DateTime.Now.Date
i have strings in the form [abc].[some other string].[can.also.contain.periods].[our match] i now want to
I have a data with the following format: foo<tab>1.00<space>1.33<space>2.00<tab>3 Now I tried to sort
Ive tried searching for hours now and cannot find out why my code (aka,
I have tried for three days now and gotten nowhere on this.... I absolutely
I've tried to find the 64bit version for pysvn for a while now. The
Now that ASP.NET MVC 2 is out , I tried to install it on
I am now learning on the audio framework of iphone. Just tried to play
I'll point out now, that I'm new to using saxon, and I've tried following
I've been wanting to learn assembly for a while now, and although I've tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.