簡體   English   中英

WordPress自定義類別頁面顯示空白頁面

[英]WordPress custom category page shows blank page

我想在WordPress網站上顯示特定類別的帖子。 類別代碼是31。這是我的代碼,

<?php
/**
 * Template Name: SSLive
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
<?php get_header(); ?>

<div id="primary">
    <div id="content" role="main">



<?php 
$args = array ( 'category' => 31, 'posts_per_page' => 5);
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post);
 ?>
//Style Posts here
<?php endforeach; ?>


    </div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>

我面臨的問題是,當我使用此頁面時,什么都沒有顯示。

為什么不使用wp_query打電話? 這個簡單且易於使用的腳本應該為您類別中的每個帖子返回一個鏈接的標題。 添加附加信息很容易,因為這就像主要的wordpress循環一樣,因此所有通用調用都可以使用,即the_contentthe_excerpt等。

       <?php
          $args = array( 'cat' => 31,);
          $loop = new WP_Query( $args );

          while ( $loop->have_posts() ) :
          $loop->the_post();
       ?> 
       <!--- Add your stuff here --->
       <!--- Title for example --->
          <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       <?php
          endwhile;
       ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM