0

我究竟做错了什么...

这是一件很愚蠢的事情。

我想订购我的帖子,但无论我订购什么和订购什么,都没有任何效果!GRRR

<?php  
        $postCount = 0;   

        remove_filter('get_the_excerpt', 'replace_ellipsis');    
        remove_filter('excerpt_length', 'my_excerpt_length');

        add_filter('get_the_excerpt', 'replace_ellipsis2');    
        add_filter('excerpt_length', 'my_excerpt_length2');

        $args = array( 
            'post_type' => 'news', 
            'posts_per_page' => 9999,
            'order' => 'ASC',
        );                                                       

        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post();
        $postCount++; 
?>

            <div class = "anArticle" style = "<?php if(!$postCount % 3 == 1){ echo 'margin-right:0px;'; } ?>" onclick = "location.href='<?php echo the_permalink(); ?>';">
                <div class = "title"><a href = "<?php echo the_permalink(); ?>"><?php if(!get_field('short_title')){echo limit_length(get_the_title(), 48);}else{echo get_field('short_title') . '...';} ?></a></div>
                <div class = "theDate"><? the_time(get_option('date_format')); ?></div>                                                                                               
                <?php if(!get_field('caption')){the_excerpt();}else{the_field('caption'); echo '...';} ?> 
                <div class = "readMore"><a href = "<?php echo the_permalink(); ?>">Read more... </a></div>  
            </div> 
<?php
        endwhile;
?>

有什么让你觉得愚蠢的事情吗?

您知道通常可以阻止帖子正确排序的任何事情吗?

4

2 回答 2

2

您没有指定要排序的字段——您只是想简单地说“按升序”而不说要使用哪个字段。

从这里改变它:

    $args = array( 
        'post_type' => 'news', 
        'posts_per_page' => 9999,
        'order' => 'ASC',
    );

对此:

    $args = array( 
        'post_type' => 'news', 
        'posts_per_page' => 9999,
        'order' => 'ASC',
        'orderby' => 'title',
    );      

看看会发生什么。

于 2012-10-29T14:32:02.547 回答
0

needed to use get_posts

<?php      
    global $post;                                        
    $postCount = 0;  
    $args = array( 'post_type' => 'news', 'order' => 'DESC' );
    $myposts = get_posts( $args );                      

    remove_filter('get_the_excerpt', 'replace_ellipsis');    
    remove_filter('excerpt_length', 'my_excerpt_length');

    add_filter('get_the_excerpt', 'replace_ellipsis2');    
    add_filter('excerpt_length', 'my_excerpt_length2');

    foreach( $myposts as $post ) :  setup_postdata($post);

        $postCount++;

    ?>     
        <div class = "anArticle" style = "<?php if(!$postCount % 3 == 1){ echo 'margin-right:0px;'; } ?>" onclick = "location.href='<?php echo the_permalink(); ?>';">
            <div class = "title"><a href = "<?php echo the_permalink(); ?>"><?php if(!get_field('short_title')){echo limit_length(get_the_title(), 48);}else{echo get_field('short_title') . '...';} ?></a></div>
            <div class = "theDate"><? the_time(get_option('date_format')); ?></div>                                                                                               
            <?php if(!get_field('caption')){the_excerpt();}else{the_field('caption'); echo '...';} ?> 
            <div class = "readMore"><a href = "<?php echo the_permalink(); ?>">Read more... </a></div>  
        </div> 
    <?php endforeach;
?>     
于 2012-10-29T14:42:44.083 回答