Wordpress查询以包括帖子和页面

Wordpress查询以包括帖子和页面,wordpress,jquery-isotope,posts,Wordpress,Jquery Isotope,Posts,我正在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_po

我正在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 -->

默认情况下,您的查询将显示帖子。添加“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 echo get_post_type( $post ) ?>

此外,如何将类添加到特定的帖子类型?例如,我希望能够区分同位素网格中的页面和帖子,允许我分配不同的宽度?干杯
<?php echo get_post_type( $post ) ?>