wordpress调用指定post type文章怎么操做

  咱们有时会用wordpress建立好几种post type文章,好比默认的post文章和product文章,若是咱们要在每一个页面的底部调用post type类型为post最新文章要如何操做呢?那咱们就须要进行改造一下了,下面就随ytkah一块儿来看看如何操做吧。php

  咱们把调用放在footer.php文件里吧,经过li列表形式调取最新发布的post文章,连接加标题,点击直接跳转到文章页wordpress

          <ul>
                    <li class="title">News</li>
                    <?php
                        $args = array( 'post_type' => 'post', 'posts_per_page' => 5 );
                        $loop = new WP_Query( $args );
                        while ( $loop->have_posts() ) : $loop->the_post();
                        echo '<li><a href="';
                        the_permalink();
                        echo '">';
                        the_title();
                        echo '</a></li>';
                        endwhile;
                    ?>
                </ul>

  展现效果以下oop

  文章内容页就用以下代码进行调取post

<?php
$args = array( 'post_type' => 'post', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;
?>

  有相同需求的朋友能够试试这种方法吧blog

  参考资料https://blog.wpjam.com/article/wordpress-post-type/it

相关文章
相关标签/搜索