简体   繁体   中英

If statement selecting nth posts in Wordpress loop

I'm working within the Wordpress loop and need to only display a featured image for posts 1, 4, 5, 8, 9, 12, 13 etc (+3+1r) in sequence.

I can set up a counter variable and count the posts but unsure how I can select nth as per the above sequence if anybody can help with the syntax please?

$posts = get_posts();

to get the last post, either

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

or

$last_post = end($posts); //sets the internal pointer of $posts to the last element

嗯,然后只需在上面的注释中使用for循环即可获取ID,然后在现有的wp循环中使用if(in_array(get_the_id(),$ids)){//dosomething}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM