gpt4 book ai didi

javascript - 作品集模板: display number of posts based on the day of the week?

转载 作者:行者123 更新时间:2023-11-28 02:27:58 25 4
gpt4 key购买 nike

这是我的第二篇文章,所以如果我遗漏了一些东西,我深表歉意!我在 WordPress 编码方面也很弱,但我正在学习!

我正在使用作品集模板来组织教育内容页面。每个页面有 5 个帖子,每个工作日(周一至周五)一个。我每周都会让不同的组访问不同的页面,但大多数页面都是“旧的”。因此,现在访问它们时,您会同时看到所有 5 天。

我希望他们只看到前几天和今天的帖子。因此,在周一访问时,您只能看到周一的帖子,即使周一至周五已发布。周三访问,您会看到周一至周三。

所有页面都是一样的,只会有 5 个帖子。这种方法没有太大的灵 active ,但是没关系。我可能会包含一个元复选框来“启用/禁用”此功能,但不需要使用那么多。

这是当前 template-portfolio.php 的链接:https://gist.github.com/4671326

这是我尝试修改的:https://gist.github.com/4661867

这是相关的代码:

$days = array(
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
);

$args = array(
'post_type' => 'portfolio',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_value' => esc_attr( get_post_meta( $post->ID, 'portsort', true ) ),
'posts_per_page' => $days[date( 'l', current_time('timestamp') )],
);

我的添加不起作用。这是我试图放入其中的逻辑:

Show #number# of posts depending on what day it is. So, if the date returns Thursday, then just show 4 posts.

对我来说,这似乎很容易做到......但由于某种原因它无法正常工作。

那么...我的问题:

  1. 这是顺利运行的适当编码逻辑吗?
  2. 我在代码本身中做错了什么?

感谢您的帮助!

最佳答案

较旧的问题,但可能只是区分大小写的问题:

$days = array(
'monday' => 1,
'tuesday' => 2,
'wednesday' => 3,
'thursday' => 4,
'friday' => 5,
);

$current_day = strtolower( date( 'l', current_time('timestamp') ) );

$args = array(
'post_type' => 'portfolio',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_value' => esc_attr( get_post_meta( $post->ID, 'portsort', true ) ),
'posts_per_page' => $days[$current_day],
);

关于javascript - 作品集模板: display number of posts based on the day of the week?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com