【问题标题】:Storing values in an array with wordpress使用 wordpress 将值存储在数组中
【发布时间】:2011-04-11 08:41:52
【问题描述】:

所以我正在尝试创建一个 wordpress 插件来存储某个月份所写帖子的所有日期。因此,如果本月 10 日、12 日和 18 日发布了帖子,我想将这些日期“10”、“12”和“18”存储在数组$stack[] 中。我是 php 新手,所以我不知道为什么这不将日期存储在数组中:

// The Query
$themonth = date( 'n', current_time( 'timestamp' ) );
query_posts('cat=4&month=' . $themonth );
// The Loop
$stack = array();
while ( have_posts() ) : the_post(); 
$stack[] = the_time('j');
endwhile;

有什么想法吗?

【问题讨论】:

    标签: php arrays wordpress


    【解决方案1】:

    把你的 while 改成这样:

    while ( have_posts() ) : 
        the_post();
        $stack[the_time('j')] = get_the_content();
    endwhile;
    

    【讨论】:

    • 这似乎将帖子的内容存储在数组中。我不需要存储内容,只需要创建帖子的月份。
    • 所以,忽略内容,只使用数组键中的日期!
    猜你喜欢
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多