Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress中,顶视图帖子未显示特色图片_Php_Wordpress_Post - Fatal编程技术网

Php 在wordpress中,顶视图帖子未显示特色图片

Php 在wordpress中,顶视图帖子未显示特色图片,php,wordpress,post,Php,Wordpress,Post,我试图在wordpress的侧边栏.php中显示我浏览量最大的帖子,并附上特色图片 我尝试了以下代码,但它重复显示了一个特征图像三次 这是一个 我的代码是: siderbar.php <div class="popular"> <h2>Most Popular Posts</h2> <?php echo popularPosts(3); ?> </div> 请建议我如何用特色图片和帖子标题显示三个最受关注的页面。试试

我试图在wordpress的侧边栏.php中显示我浏览量最大的帖子,并附上特色图片

我尝试了以下代码,但它重复显示了一个特征图像三次

这是一个

我的代码是:

siderbar.php

<div class="popular">
<h2>Most Popular Posts</h2>

    <?php echo popularPosts(3); ?>

</div>   
请建议我如何用特色图片和帖子标题显示三个最受关注的页面。

试试wordpress插件:


这可能对你有帮助

尝试
获取\u post\u缩略图($id)
而不是
现在可以使用的\u post\u缩略图()
。。非常感谢
<?php

function popularPosts($num) {
global $wpdb;

$posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM   $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");

foreach ($posts as $post) {
    setup_postdata($post);
    $id = $post->ID;
    $title = $post->post_title;
    $count = $post->comment_count;

    if ($count != 0) {
        $popular .= '<li>';
        $popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '">' . $title .the_post_thumbnail(). '</a> ';
        $popular .= '</li>';
    }
}
return $popular;
   }

   ?>
 function bac_PostViews($post_ID) {

     //Set the name of the Posts Custom Field.
     $count_key = 'post_views_count'; 

     //Returns values of the custom field with the specified key from the specified post.
     $count = get_post_meta($post_ID, $count_key, true);

     //If the the Post Custom Field value is empty. 
     if($count == '')
     {
          $count = 0; // set the counter to zero.

          //Delete all custom fields with the specified key from the specified post. 
          delete_post_meta($post_ID, $count_key);

          //Add a custom (meta) field (Name/value)to the specified post.
          add_post_meta($post_ID, $count_key, '0');
          return $count . ' View';

          //If the the Post Custom Field value is NOT empty.
     }else{
          $count++; //increment the counter by 1.
          //Update the value of an existing meta key (custom field) for the specified post.
          update_post_meta($post_ID, $count_key, $count);

          //If statement, is just to have the singular form 'View' for the value '1'
          if($count == '1')
          {  
               return $count . ' View';
          }
          //In all other cases return (count) Views
          else 
          {
               return $count . ' Views';
          }
       }
    }
?>