admin管理员组文章数量:1326112
I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.
Here is my code:
<?php do_action( 'hitmag_before_content' ); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<h1>Latest News</h1>
<?php do_action( 'hitmag_before_blog_posts' ); ?>
<?php $args = array(
'post_type' => 'post' ,
'orderby' => 'date' ,
'order' => 'DESC' ,
'posts_per_page' => 3,
'category' => '30','33','1',
'paged' => get_query_var('paged'),
'post_parent' => $parent
); ?>
<?php query_posts($args); ?>
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
$archive_content_layout = get_option( 'archive_content_layout', 'th-grid-2' );
echo '<div class="posts-wrap ' . esc_attr( $archive_content_layout ) . '">';
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
echo '</div><!-- .posts-wrap -->';
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php do_action( 'hitmag_after_blog_posts' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.
Here is my code:
<?php do_action( 'hitmag_before_content' ); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<h1>Latest News</h1>
<?php do_action( 'hitmag_before_blog_posts' ); ?>
<?php $args = array(
'post_type' => 'post' ,
'orderby' => 'date' ,
'order' => 'DESC' ,
'posts_per_page' => 3,
'category' => '30','33','1',
'paged' => get_query_var('paged'),
'post_parent' => $parent
); ?>
<?php query_posts($args); ?>
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
$archive_content_layout = get_option( 'archive_content_layout', 'th-grid-2' );
echo '<div class="posts-wrap ' . esc_attr( $archive_content_layout ) . '">';
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
echo '</div><!-- .posts-wrap -->';
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php do_action( 'hitmag_after_blog_posts' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
Share
Improve this question
asked Aug 12, 2020 at 16:04
Imtango30Imtango30
1425 bronze badges
2 Answers
Reset to default 0The short answer is that the value for category
should be an array of IDs.
The longer answer is that it is rarely appropriate to use query_posts
at all.
Use category__in instead of category.
So just replace:
'category' => '30','33','1',
with
'category__in' => array( '30','33','1'),
本文标签: blog pageDisplay latest posts from a specific categories
版权声明:本文标题:blog page - Display latest posts from a specific categories 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192429a2430460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论