調(diào)用該分類目錄下所有文章及其鏈接
一、帶分頁的
將“news”改為自己需要的分類目錄的名稱即可調(diào)用改分類下所有的文章鏈接,調(diào)用目錄分頁需要一個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>
- <!-- 顯示評論數(shù) -->
- <!-- 顯示發(fā)布日期 -->
- <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”改為自己需要的分類目錄的名稱即可調(diào)用改分類下所有的文章鏈接
- <?php
- $args=array(
- 'cat' => get_cat_id('news'), // 分類ID
- 'posts_per_page' => 1000, // 顯示篇數(shù)
- );
- 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(); ?>
新聞熱點
疑難解答
圖片精選