我正在使用特定的代码片段在父页面上显示子页面名称,精选图像和摘录。这段代码工作正常,但我一直在尝试修改它,以便按字母顺序显示子帖子,但没有成功。
我尝试将ORDER BY menu_order更改为ORDER BY标题或ORDER BY名称,但它会破坏页面。
如果有人提供一些提示或提示,我们将非常感谢您的建议!
<?php
$pageChildren = $wpdb->get_results("
SELECT *
FROM $wpdb->posts
WHERE post_parent = ".$post->ID."
AND post_type = 'page'
ORDER BY menu_order
", 'OBJECT');
if ( $pageChildren ) :
foreach ( $pageChildren as $pageChild ) :
setup_postdata( $pageChild );
?>
<?php $imagethumb = get_post_meta($pageChild->ID, 'image-thumb', $single = true); ?>
<div id="solutionbutton">
<div id="centerbutton">
<img src="<?php echo $imagethumb; ?>" />
<h4><?php print '<a href="' . get_permalink( $pageChild->ID ) . '">' . get_the_title( $pageChild->ID ) . '</a>'; ?></h4>
</div>
<div id="entry">
<?php echo excerpt(13); ?>
</br></br>
<a href="<?php echo get_permalink($pageChild->ID); ?>">Read More...</a>
</div>
</div>
<?php
endforeach;
endif;
?>
</div>
答案 0 :(得分:0)
试试这个:
$pageChildren = $wpdb->get_results("
SELECT *
FROM $wpdb->posts
WHERE post_parent = ".$post->ID."
AND post_type = 'page'
ORDER BY post_title
", 'OBJECT');
用于页面。但是否有指定发布父级的功能?如果是,请将post_type = 'page'
更改为post_type = 'post'
。
顺便说一句,您的代码可以使用WordPress内置函数重构,如下所示:
$pageChildren = get_posts(array(
'post_type'=>'page',
'nopaging'=>true,
'orderby'=>'menu_order'
));
答案 1 :(得分:0)
**Try the code.....**
$args = array(
'orderby' => 'title',
'order'=> 'DESC',
'post_parent' => $post->ID,
'post_type' => 'page'
);
$get_childrens = get_children($args);
print_r($get_childrens);