Foreach循环 - 按日期排序 - 自定义日期格式

时间:2014-08-30 21:45:35

标签: php xml wordpress parsing

提前感谢您的帮助。

我的问题很简单,但有点不可及!我基本上从一个Wordpress设置中拉出帖子以显示在另一个上。使用XML我已经创建了Feed并成功提取了所有信息。然而,我遇到的一个问题是像我在Wordpress设置中那样订购帖子。我已通过自定义字段" sortin_date"订购帖子,然后使用Wordpress循环按此日期订购帖子(代码如下):

WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 4, 'meta_key'=>'sortin_date',  'orderby' => 'sortin_date', 'order' => ASC, 'caller_get_posts'=> -1 ) );

" sortin_date"字段输出为:YYYYMMDD

然而,显然我不能在我的php解析脚本上使用简单的Wordpress循环。我的问题是,如何使用foreach循环实现上述相同的循环? (以下代码):

<?php
    $prodFeed = simplexml_load_file('myxmllink.xml');
    foreach ($prodFeed->item as $product):
        $c++;

        $title=$product->title;
        $link=$product->link['href'];
        $info=$product->info;

        if( $c % 2 != 0) { echo '<li>'; }
        else { echo '<li class="hlight">'; }

        echo '<a href="' . $link . '">' . $title . '</a><span class="workshop_date">' . $info . '</span></li>';

        if ($c == 4) break;
    endforeach;
?>

示例XML项(sortDate是&#34; sortin_date&#34;):

    <item>
                <id>2799</id>
                <title><![CDATA[Fascial Release for Structural Balance:  Fans of the Hips]]></title>
                <link>http://www.thelink.com/</link>
                <author>john</author>
                <sortDate>20150522</sortDate>
                <info><![CDATA[22/23/24 May '15 &mdash; Amsterdam, Netherlands]]></info>
</item>

0 个答案:

没有答案
相关问题