WordPress的我查询后不
显示我的岗位我是新来的wordpress,我有一个具有提供的CATEGORY_NAME后,它有一个内容,这里是固定链接:http://localhost/jcjohn/2016/09/20/what-we-offer/
WordPress的我查询后不
现在我想从我的章节页面显示我的文章的内容。
这里是我的部分内部代码:
<section id = "offer">
<?php
$args = array(
'type' => 'post',
'posts_per_page' => 3,
'category_name' => 'offer',
);
$offerBlog = new WP_Query($args);
if ($offerBlog->have_post()):
while ($offerBlog->have_posts()):
$offerBlog->the_post();
get_template_part('content', get_post_format());
endwhile;
endif;
wp_reset_postdata();
?>
</section>
因此,这里是你需要做的,以显示单页上的帖子内容。你似乎已经错过了have_post
的s
所以它需要像下面
注:这里面去index.php
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'category_name' => 'offer',
);
$offerBlog = new WP_Query($args);
?>
<!-- Blog Article -->
<section id="blog">
<?php
if ($offerBlog->have_posts()) :
while ($offerBlog->have_posts()) : $offerBlog->the_post();
the_content();
endwhile;
else : ?>
<div class="no-content">
<h3>Well... it looks like we forgot to put content here.</h3>
</div>
<?php
endif;
wp_reset_postdata();
?>
</section>
谢谢..已显示 –
您尝试使用这个循环与您具有创建类别的cat_id
。
query_posts(array('cat' => '1', 'posts_per_page' => 5, 'orderby' => 'title', 'order' => 'DESC'));
您可以尝试更换后的代码,如下所示。
<section id = "offer">
<?php
$args = array(
'post_type' => 'post',
'cat' => '1',
'posts_per_page' => 5,
'orderby' => 'title',
'order' => 'DESC'
);
$offerBlog = new WP_Query($args);
if ($offerBlog->have_posts()):
while ($offerBlog->have_posts()):
$offerBlog->the_post();
get_template_part('content', get_post_format());
endwhile;
endif;
wp_reset_postdata();
?>
</section>
您错过了循环格式。
参考:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Kuhmar.P Thank you for你的答案先生,我应该把那个先生放在哪里?对不起,我只是一个初学者,我可以把它放在我的$ args中吗? –
只需放置'cat'=>'1','posts_per_page'=> 5,'orderby '=>'title','order'=>'DESC'' in $ args by 012 old old $ args。 –
and include'post_type => post' also also in $ args .. –
变“型”到$ args变量“post_type”。 – vrajesh
@vrajesh谢谢你的回答,先生。仍然没有输出先生。请帮忙 –
尝试:将get_template_part()函数替换为the_content(); @jc John ..注意到您在“post_type”中添加了帖子作为'post'.. – vrajesh