[英]WordPress custom category page shows blank page
I want to display a posts from a specific category on a WordPress website. 我想在WordPress网站上显示特定类别的帖子。 The category code is 31. Here is my code,
类别代码是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(); ?>
The issue that I am facing is that when I use this page, nothing shows up. 我面临的问题是,当我使用此页面时,什么都没有显示。
why don't you call using wp_query? 为什么不使用wp_query打电话? Nice and easy to use, this simple script should return you a linked title for each of the posts in your category.
这个简单且易于使用的脚本应该为您类别中的每个帖子返回一个链接的标题。 Adding additional informatio is easy as this is just like the main wordpress loop so all the generic calls will work ie
the_content
, the_excerpt
etc. 添加附加信息很容易,因为这就像主要的wordpress循环一样,因此所有通用调用都可以使用,即
the_content
, the_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.