儿童页面的Wordpress排序

时间:2017-01-06 12:01:54

标签: wordpress

我正在尝试使用最新的第一页列出当前页面的子页面,但我只能按字母顺序显示它。设置orderby并没有任何区别。

<?php
global $post;
$currentPage = $post->ID;
// Get posts (tweak args as needed)
$args = array(
        'child_of' => $currentPage,
        'post_type' => 'page',
        'orderby' => 'date',
        'order' => 'ASC'
    );
    $posts = get_pages( $args );
    foreach (array_chunk($posts, 1, true) as $posts) :  ?>
    <?php foreach( $posts as $post ) : setup_postdata($post); ?>
        <?php $img = wp_get_attachment_image_src( get_post_meta($post->ID, 'image_or_video', true)); ?>
        <?php $video = get_post_meta($post->ID, 'embedded_video', true); ?>
        <?php $alt_text_for_logo = get_post_meta($post->ID, 'article_name', true); ?>
        <?php $short_description = get_post_meta($post->ID, 'article_short_description', true); ?>
        <?php if( $img || $video ): ?>
        <div class="column small-4 medium-4 large-4 card white margin-bottom"> 
            <div>
                <a href="<?php the_permalink(); ?>">
                    <?php if( $img ): ?>
                        <img src="<?php echo $img[0]; ?>" alt="<?php echo $alt_text_for_logo; ?>" />
                    <?php endif; ?>
                    <?php if( $video ): ?>
                        <?php the_field('embedded_video'); ?>
                    <?php endif; ?>
                    <h4><?php the_title(); ?></h4>
                    <p><?php the_field('article_short_description'); ?></p>
                    <p class="tag"><?php echo get_the_title( $post->post_parent ); ?></p>
                </a>
            </div>
        </div>
    <?php endif; ?>
<?php endforeach; ?>

4 个答案:

答案 0 :(得分:1)

sort_order设置为 desc ,将sort_column设置为 ID

$args = array(
        'child_of' => $currentPage,
        'post_type' => 'page',
        'sort_column' => 'ID',
        'sort_order' => 'desc'
    );

答案 1 :(得分:0)

根据WordPress查询:https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters 您需要像这样更改查询:

$args = array(
    'child_of'  => $currentPage,
    'post_type' => 'page',
    'orderby'   => 'date',
    'order'     => 'DESC'
);

我希望有所帮助。

答案 2 :(得分:0)

根据文档page,您应该使用:

'sort_order' => 'asc', 'sort_column' => 'date',

答案 3 :(得分:0)

尝试

删除// Encoding/decoding [0..1) floats into 8 bit/channel RGBA. Note that 1.0 will not be encoded properly. inline float4 EncodeFloatRGBA( float v ) { float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 16581375.0); float kEncodeBit = 1.0/255.0; float4 enc = kEncodeMul * v; enc = frac (enc); enc -= enc.yzww * kEncodeBit; return enc; } inline float DecodeFloatRGBA( float4 enc ) { float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/16581375.0); return dot( enc, kDecodeDot ); } 并制作可解决问题的f = R + 255 * G + 65025 * B + 16581375 * A

所以参数$ args将是

'orderby' => 'rand',

或者您可以使用post_date

'order' => 'DESC'