[英]Show only parent category post
I want to show only parent category post. 我只想显示父类别的帖子。 like i have create 1 category (pritesh : Parent category) in wordpress and add 2 post in this category the i have create another category (Nilesh - Child cateory) but this is the child category of first one and then i have add 2 more article in this category now i have run my code then when i use first category
就像我在wordpress中创建1个类别(pritesh:父类别)并在该类别中添加2个帖子,我创建了另一个类别(Nilesh-Child类别),但这是第一个类别,然后我又添加了2个文章在此类别中,现在我已经运行了代码,然后在使用第一类别时
======================================================================== ================================================== ======================
$args = array(
'posts_per_page' => 5,
'offset' => 0,
'category_name' => 'pritesh',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$output = '<ul>';
$myposts = get_posts( $args );
Now i print $myposts variable then Nilesh category posts will showing. 现在我打印$ myposts变量,然后将显示Nilesh类别的帖子。 But i want only Pritesh category posts.
但我只想要Pritesh类别的帖子。 How i do that.
我该怎么做。 I have tried many code but not works.
我尝试了很多代码,但没有用。
You can use 'is_category()' or 'in_category()' just before echoing your post. 您可以在回显您的帖子之前使用“ is_category()”或“ in_category()”。
<?php
if ( in_category('fruit') ) {
include 'single-fruit.php';
} elseif ( in_category('vegetables') ) {
include 'single-vegetables.php';
} else {
// Continue with normal Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// ...
}
?>
In your case : 在您的情况下:
<?php
if ( is_category('Nilesh') )
{
// Continue with normal Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// ...
}
?>
For more information, check this out: http://codex.wordpress.org/Function_Reference/is_category 有关更多信息,请查看以下内容: http : //codex.wordpress.org/Function_Reference/is_category
Also this support ticket . 还有这张支持票 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.