调用该分类目录下所有文章及其链接
一、带分页的
将“news”改为自己需要的分类目录的名称即可调用改分类下所有的文章链接,调用目录分页需要一个wordpress插件wp-pagenavi链接:https://pan.baidu.com/s/1o7DFyCq 密码:xbxp
- <?php
- $order_by = 'comment_count';
- $order = 'DESC';
- $posts_per_page = 5;
- $cat = get_cat_id('news');
- global $post;
- $post_title = $post->post_title;
- $post_content = apply_filters('the_content', $post->post_content)
- ?>
- <?php
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $post_list = new WP_Query(
- "posts_per_page=" . $posts_per_page .
- "&orderby=" . $order_by .
- "&order=" . $order .
- "&cat=" .get_cat_id('news').
- "&paged=" . $paged
- );
- $total_posts = $post_list->found_posts;
- ?>
- <?php if ( $post_list->have_posts() ) : ?>
- <div class="entry-content">
- <ul class="news-list">
- <?php while ( $post_list->have_posts() ) : $post_list->the_post(); ?>
- <li>
- <!-- 带连接的文章标题 -->
- <strong><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></strong>
- <span><?php the_field('wenzhang-time');?></span>
- <!-- 显示评论数 -->
- <!-- 显示发布日期 -->
- <p> <?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 270,"……"); ?></p>
- </li>
- <?php endwhile; ?>
- </ul>
- <!-- 用wp_pagenavi插件分页 -->
- <?php if ( function_exists('wp_pagenavi') ) wp_pagenavi( array('query' => $post_list) ); ?>
- </div><!-- .entry-content -->
- <!-- 文章列表显示结束 -->
- <?php endif; ?>
二、不带分页
将“news”改为自己需要的分类目录的名称即可调用改分类下所有的文章链接
- <?php
- $args=array(
- 'cat' => get_cat_id('news'), // 分类ID
- 'posts_per_page' => 1000, // 显示篇数
- );
- query_posts($args);
- if(have_posts()) : while (have_posts()) : the_post();
- ?>
- <li>
- <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong> <span><?php the_field('wenzhang-time');?></span>
- <p>
- <?php if (has_excerpt()) {
- echo $description = get_the_excerpt(); //文章编辑中的摘要
- }else {
- echo mb_strimwidth(strip_tags(apply_filters('the_title();', $post->post_title)), 0, 27,"…");
- } ?>
- </p>
- </li>
- <?php endwhile; endif; wp_reset_query(); ?>
新闻热点
疑难解答
图片精选