隔行扫描海报查询

时间:2015-03-19 14:04:40

标签: php wordpress

我想按照以下顺序在我的wordpress主页上显示帖子:

sticky0 normal0 normal1 normal2 stycky1 normal3 normal4 normal5

这样做我想我需要使用两个customs query

问题不是the query to get sticky post and to get normal post without stycky,而是隔离loop的过程。

1 个答案:

答案 0 :(得分:0)

在你的主题index.php中:

<?php if( have_posts() ): ?>

<?php
    $stickies = array();
    $query = new WP_Query( *args* );
    if( false !== $query ) {
        $stickies = $query->get_posts();
    }
    $i = 0;
    $i2 = 0;

    while( have_posts() ){
        if( isset( $stickies[$i2] ) && ($i == 0 || $i == 3) ){
            // display your sticky
            setup_postdata($stickies[$i2]);
            get_template_part('content', 'sticky');
            $i2++;
        } else {
            // display normal post
            the_post();
            get_template_part('content', get_post_type());
        }
        i++;
    }
?>

<?php endif; ?>