如何让热门帖子出现在后轮播中

时间:2016-08-25 15:35:52

标签: wordpress owl-carousel

我在本教程之后添加了猫头鹰旋转木马到我的Wordpress主题 - http://www.web2feel.com/making-a-featured-post-carousel-slider-with-wp-customizer-controls/ - 我已正确添加了旋转木马,但现在我希望它能自动显示热门帖子。现在它显示了某个类别中的帖子,例如“新闻”。任何人都可以帮我这个吗?

这是我的carousel.php

<div id="slider">
 
    <?php
    $carousel_cat = get_theme_mod('carousel_setting','1');
    $carousel_count = get_theme_mod('count_setting','4');
    $new_query = new WP_Query( array('showposts' => $carousel_count, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' )); ?>
 
    <div class="item">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'carousel-pic' ); ?></a>
        <h3> <?php the_title();?> </h3>
    </div>
 
    <?php 
        endwhile;
        wp_reset_postdata(); 
    ?>
 
</div>

1 个答案:

答案 0 :(得分:1)

  

对carousel.php文件的更改将构成这里的技巧,以显示轮播滑块中的热门帖子。

这是一个技巧,你将跟进并破解代码。

<div id="slider"> 
<?php
$carousel_cat = get_theme_mod('carousel_setting','1');
$carousel_count = get_theme_mod('count_setting','4');
$month = date('m');
$year = date('Y');
$new_query = new WP_Query( array('posts_per_page' => $carousel_count, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC')); ?>
<?php if ( $new_query->have_posts() ) : ?>
<?php while ( $new_query->have_posts() ) : $new_query->the_post(); ?>
<div class="item">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
<?php // the_post_thumbnail('thumbnail'); Thumbnail (150 x 150 hard cropped) If you want anyother size you can change ?>
<h3> <?php the_title();?> </h3>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, No Popular Posts Found ' ); ?></p>
<?php endif; ?>
</div>