我做错了什么......
这是愚蠢的事。
我想订购我的帖子,但无论我按顺序排序和订购,都没有用!哎呀
<?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;
?>
任何让你眼前一亮的东西都是愚蠢的?
你知道什么通常可以阻止帖子正确排序?
答案 0 :(得分: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',
);
看看会发生什么。
答案 1 :(得分:0)
需要使用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;
?>