在wordpress post循环中跳过三个帖子

时间:2018-05-24 04:26:22

标签: wordpress

如何在 wordpress 帖子循环中跳过三个帖子?感谢。

public TripleString() {
    string1 = DEFAULT_STRING;
    string2 = DEFAULT_STRING;
    string3 = DEFAULT_STRING;
}
public TripleString(String str1, String str2, String str3) {
   string1 = DEFAULT_STRING;
   string2 = DEFAULT_STRING;
   string3 = DEFAULT_STRING;
   this.setString1(str1);
   this.setString2(str2);
   this.setString3(str3);
}
public boolean setString1(String str1) {
    if (str1.length() < MIN_LEN || str1.length() > MAX_LEN) {
        return false;
    } else {
        string1 = str1;
        return true;
    }
}
public String getString1() {
    return string1;
}
public String toString(){
    return "string1 = "+string1+"; string2 = "+string2+"; string3 = "+string3 + "\n";
}

2 个答案:

答案 0 :(得分:1)

在functions.php中添加此代码

add_action('pre_get_posts', 'skip_posts_wordpress');
function skip_posts_wordpress($query){

    if(!is_admin() && $query->is_archive()){
        $query->set('offset', 3);
    }
}

或尝试

$query_custom = new WP_Query( array( 'offset' => 3 ) );
 while ( $query_custom->have_posts() ) : $query_custom->the_post();
      include( locate_template( 'content-' . $style . '.php' ) );
 endwhile; 

答案 1 :(得分:0)

你只需要添加:

$query_custom = new WP_Query( array( 'offset' => 3 ) );

while ( $query_custom->have_posts() ) : $query_custom->the_post();