多个Wordpress循环 [英] Multiple Wordpress Loops

查看:104
本文介绍了多个Wordpress循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个经过修改的WordPress循环,并且试图实现一个出现在索引文件中的一类" 多个wordpress循环.

I'm working on a modified WordPress loop and I'm trying to achieve is a "sort of" multiple wordpress loops that will appear on my index file.

我的目标是创建以下内容:

My goal is to create the following:

循环#1:一个WP循环,将显示(最新和最近发布的)帖子编号1、2和3.

Loop #1: a WP loop that will display the (latest and the most recent published) post number 1, 2 & 3.

循环2:一个WP循环,将显示(最新和最近发布的)帖子编号4、5、6、7、8和9. 9

Loop #2: a WP loop that will display the (latest and the most recent published) post number 4, 5, 6, 7, 8 & 9

循环3:一个WP循环,将显示(最新和最近发布的)帖子编号10、11、12和13

Loop #3: a WP loop that will display the (latest and the most recent published) post number 10, 11, 12 & 13

循环#4:一个WP循环,将显示(最新和最近发布的)帖子编号14& 15

Loop #4: a WP loop that will display the (latest and the most recent published) post number 14 & 15

第5循环:一个WP循环,将显示所有剩余的帖子(不包括第1到15的帖子,该帖子已由第1-4循环显示).

Loop #5: a WP loop that will display the all the remaining post (this excludes post #1 to 15, which was already displayed by the Loop#1-4).

*第1-5个循环将包装成一个循环,并将在我的索引文件中运行.

*Loops 1-5 will be wrapped up in to one loop and will run in my index file.

我知道,任何人都可以说我可以在一个简单的wordpress循环中做到这一点.但这背后的原因是每个Loops都有自己独特的HTML结构(这实际上是我的计划).

I know, anyone can argue that I can do this in a simple wordpress loop. but the reason behind this is each Loops has it's own unique HTML Structure (this is actually my plan).

在循环5中,我尝试使用<?php query_posts('offset=15'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>但该方法的问题是它在WP分页中效果不佳.问题是当我尝试移至下一页"时,或将显示同一组帖子,即帖子#16等.

In the Loop #5, I have tried using the <?php query_posts('offset=15'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> BUT the problem with this approach is it didn't worked well with the WP pagination. The problem is the when I tried to move to the Next Page or, the same set of post will be displayed which is the post #16 etc.

我正在寻求您任何人都可以提供的帮助.我是WP Loops的菜鸟,并且具有非常基础的PHP.

I am seeking your help and assistance that anyone could provide. I am a noob in WP Loops and has a very basic skills PHP.

谢谢大家的帮助.

推荐答案

最好的解决方案是使用if和一个迭代器进行单个循环.像这样:

You best solution would be to do a single loop with if's and an iterator. Like so:

$i = 1;
while (have_posts()) {
    if ($i <= 3) {
        [...]
    } elseif ($i <= 9) {
        [...]
    } elseif ($i <= 13) {
        [...]
    } elseif ($i <= 15) {
        [...]
    } else {
        [...]
    }
    $i++;
}

我建议将每个段分成一个在每个if语句中调用的函数/方法,以帮助保持整洁,但这就是您的调用.

I would suggest separating each segment into a function/method that you call in each if statement to help keep things neat, but that is your call.

这篇关于多个Wordpress循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆