思路:

如果使用默认的wordpress的方法,调出来的数据就会被后台的显示个数所限制,而我们需要的是自由控制文章数和翻页,所以我使用WP_Query

WordPress主题开发实例:获取当前分类的文章列表

获取当前分类的方法可以通过 get_query_var('cat');

分页通过get_query_var('paged')

<?php
$cat_query=new WP_Query(array(
    'cat' => get_query_var('cat'),
    'posts_per_page'=>12,
  'paged'=>get_query_var('paged')
)); ?> <?php if($cat_query->have_posts()) : while($cat_query->have_posts()) : $cat_query->the_post(); ?> //调用文章对应内容 <?php endwhile;?>
//分页参考:http://www.cnblogs.com/tinyphp/p/6361901.html <?php endif;?>

 

 

 

快捷替换以上红字部分:

标题与链接:

WordPress主题开发实例:获取当前分类的文章列表

<li>
   <a href="<?php the_permalink();?>"> 
        <?php the_title();?>
    </a>
   <span><?php the_time('Y-m-d');?></span>
</li>

 

 

缩略图与文字:

<li>
   <a href="<?php the_permalink();?>"> 
       <?php if ( has_post_thumbnail() ) : ?>
        <?php the_post_thumbnail( 'thumbnail' ); ?>
        <?php else: ?>
        //显示默认图片
        <?php endif; ?>
    </a>
    <h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
</li>

 

相关文章:

  • 2022-12-23
  • 2021-11-25
  • 2021-08-27
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-05-02
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2021-11-30
  • 2022-12-23
  • 2021-12-06
  • 2022-02-12
  • 2022-02-24
  • 2022-12-23
相关资源
相似解决方案