我正在wordpress网站中实现同位素脚本,并且当前具有以下查询来填充网格。我希望Wordpress页面与帖子一样对待,这可以实现吗?
提前感谢你的帮助。
<?php $the_query = new WP_Query( 'posts_per_page=10' ); //Check the WP_Query docs to see how you can limit which posts to display ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "category" ); //Get the terms for this particular item
$termsString = ""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug.' '; //create a string that has all the slugs
}
?>
<article class="<?php echo $termsString; ?> isotope-brick">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ?>
</article><!-- end article -->
<?php endwhile; ?>
</div> <!-- end isotope-grid -->
答案 0 :(得分:0)
您的查询默认会显示帖子。添加'post_type'参数以包含页面。
变化:
<?php $the_query = new WP_Query( 'posts_per_page=10' ); //Check the WP_Query docs to see how you can limit which posts to display ?>
要:
<?php $the_query = new WP_Query( array(
'post_type' => array( 'post', 'page', ),
'posts_per_page' => 10,
) ); ?>
答案 1 :(得分:0)
在回答评论时:为不同的帖子类型分配一个类,我找到了一个解决方案。只需将以下内容添加到相关内容
即可<?php echo get_post_type( $post ) ?>