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

相關文章
相關標籤/搜索