Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Wordpress循环中选择第n个帖子的If语句_Php_If Statement_Wordpress - Fatal编程技术网

Php 在Wordpress循环中选择第n个帖子的If语句

Php 在Wordpress循环中选择第n个帖子的If语句,php,if-statement,wordpress,Php,If Statement,Wordpress,我在Wordpress循环中工作,只需要按顺序显示帖子1、4、5、8、9、12、13等+3+1r的特征图像 我可以设置一个计数器变量并计算帖子数,但不确定如何按照上面的顺序选择第n个,如果有人能帮忙语法的话,请 $posts = get_posts(); 为了得到最后一个帖子 $last_post = array_pop($posts); //removes it from the array 或 啊,那么只需在上面的注释中使用for循环来获取id,然后在您现有的wp循环中使用ifin_ar

我在Wordpress循环中工作,只需要按顺序显示帖子1、4、5、8、9、12、13等+3+1r的特征图像

我可以设置一个计数器变量并计算帖子数,但不确定如何按照上面的顺序选择第n个,如果有人能帮忙语法的话,请

$posts = get_posts();
为了得到最后一个帖子

$last_post = array_pop($posts); //removes it from the array


啊,那么只需在上面的注释中使用for循环来获取id,然后在您现有的wp循环中使用ifin_arrayget_id,$IDs{//dosomething}

谢谢您的回答,但是我如何扩展$posts=get_posts;如果按顺序发布1、4、5、8、9等,然后显示特征图像?您可以使用WP\u Query,lilke:$Query=newwp\u Query数组'post\u in'=>数组2、5、12、14、20;或者,简单地为这些帖子创建一个标签/类别,而不是经历所有这些!你可以参考这本wordpress抄本,我需要以编程方式选择文章,而不是手动输入ID,这不会起作用。也不会创建标记/类别。在索引页上的文章样式将交替,我需要显示他们在一个特定的方式取决于交替,即我的序列上面。它需要一个$i=计数器或类似的东西来完成。这就是你要找的吗$职位数目=12$y=1$z=1$ids=阵列1;对于$i=1$i$id;我的错,我手机上的网络似乎不工作,没有收到你回复的通知。是的,刚刚看到你的另一篇帖子。问题更清楚,答案也更好
$last_post = end($posts); //sets the internal pointer of $posts to the last element