我试图从特定类别(3篇帖子)中获取最新信息,但代码似乎不起作用。它不是显示上述类别中的帖子,而是显示第一个类别中的帖子。
这是我的代码:
<?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 -->
SO网友:chirox
在中使用category\\uu,而不是category。
因此,只需更换:
\'category\' => \'30\',\'33\',\'1\',
使用
\'category__in\' => array( \'30\',\'33\',\'1\'),