我使用以下代码在wordpress中使用特色图片的页面上显示我的帖子:
$mypages = get_pages( array() );
if ( !empty( $mypages ) ) {
echo '<ul>';
foreach ( $mypages as $mypage ) {
if ( get_the_post_thumbnail( $mypage->ID ) ) {
echo '<div class="featured-container">';
echo '<div class="featured-image">';
echo '<li><a class="feat-hover" href="' . get_permalink( $mypage->ID ) . '">' . get_the_post_thumbnail( $mypage->ID ) . '</a></li>';
echo '</div>';
echo '<div class="featured-text">';
echo '<a href="' . get_permalink( $mypage->ID ) . '">' . get_the_title($mypage->ID ) . '</a>';
echo '</div>';
echo '</div>';
}
}
echo '</ul>';
}
但在打印此信息之前,我想对$ mypages数组进行排序,以便按发布日期显示。香港专业教育学院尝试了这段代码:
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'post_date',
);
$mypages = get_pages($args);
?>
但它似乎没有用,我错过了什么或做错了吗?
提前谢谢。使用完整代码:
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'post_date'
);
$mypages = get_pages( array($args) );
if ( !empty( $mypages ) ) {
echo '<ul>';
foreach ( $mypages as $mypage ) {
if ( get_the_post_thumbnail( $mypage->ID ) ) {
echo '<div class="featured-container">';
echo '<div class="featured-image">';
echo '<li><a class="feat-hover" href="' . get_permalink( $mypage->ID ) . '">' . get_the_post_thumbnail( $mypage->ID ) . '</a></li>';
echo '</div>';
echo '<div class="featured-text">';
echo '<a href="' . get_permalink( $mypage->ID ) . '">' . get_the_title($mypage->ID ) . '</a>';
echo '</div>';
echo '</div>';
}
}
echo '</ul>';
}
答案 0 :(得分:3)
问题在于您将$args
传递给另一个array()
。您只需直接传递$args
,因为它已经是array()
。将顶部代码块更改为:
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'post_date'
);
$mypages = get_pages( $args );