我想在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(); ?>
我面临的问题是,当我使用此页面时,没有任何内容显示出来。请指导我。感谢。
答案 0 :(得分:0)
为什么不用wp_query打电话?这个简单的脚本很好用且易于使用,应该为您的类别中的每个帖子返回一个链接标题。添加额外的信息很容易,因为这就像主要的wordpress循环一样,所以所有通用调用都可以工作,即$addsContent = $Adds->selectAdds(10);
$sharedArticlesContent = $SharedContent->getSharedContent($topic_selected, $filter_selected);
$blogPostsContent = $BlogPosts->getRecentBlogPostsByTopic("business");
$contentArray = array(
$sharedArticlesContent,
$addsContent ,
$blogPostsContent
);
foreach($contentArray as $value)
{
if(count($value)>$maxLength)
{
$maxLength = count($value);
}
}
for($i=0; $i<$maxLength; $i++)
{
foreach($contentArray as $value)
{
if(isset($value[$i]))
{
if($value==$sharedArticlesContent){
$data = $value[$i];
foreach($sharedArticlesContent as $data){
$post_id = $data['id'];
$uploaded_by = $data['uploaded_by'];
$text = $data['text'];
$image = $data['image'];
require 'template1.php';
}
}elseif($value==$addsContent){
//template2
}else{
//template3
}
}
}
}
, yourString = yourString.Replace("#> + <#", "#>,<#");
等。
the_content