按时间顺序排序,而不是菜单顺序

时间:2014-05-07 10:13:05

标签: php wordpress

我使用以下代码显示所有子页面的缩略图,这是我在网上找到的代码,并且是我的客户端网站自定义的。

我正在尝试将其自定义为按最新页面排序到最旧而不是菜单顺序,但是当我将menu_order替换为日期时它只显示什么?

知道我怎么能这样做吗?非常感谢

    <?php
    $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
    $i = 0;
    if ( $child_pages ) :
    foreach ( $child_pages as $pageChilds ) :
        $gchild_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$pageChilds->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');
        if($gchild_pages) :
        foreach ($gchild_pages as $pageChild):
        setup_postdata( $pageChild );
        $thumbnail = get_the_post_thumbnail($pageChild->ID, 'work-thumb');
        if($thumbnail == "") continue; // Skip pages without a thumbnail

    ?>

       <div class="child-thumb">
        <p><a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark"><?= $thumbnail ?></a></p>
       <h3><a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark" title="<?= $pageChild->post_title ?>"><?= $pageChild->post_title ?></a></h3>
       </div>
    </a>
<?

    endforeach;
    endif;
endforeach;
endif;
?>

1 个答案:

答案 0 :(得分:1)

尝试使用

$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY `date`", 'OBJECT');