繁体   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