0

由于 Genisis 框架中的某些原因,wordpress 以下代码没有拉出子页面及其特色图像

 add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
   $classes[] = 'portfolio';
return $classes;
}

add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content'         ); // Force Full-Width Layout
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' ); // Removes     breadcrumbs
remove_action( 'genesis_post_title','genesis_do_post_title' ); // Removes post title
remove_action( 'genesis_post_content', 'genesis_do_post_content' ); // Removes content
add_action( 'genesis_post_content', 'child_do_content' ); // Adds your custom page code/content

     // Do Custom Content
function child_do_content() { ?>

<?php global $wpdb; ?>
<?php the_content(); ?>
<?php
$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
 <a href="<?php echo  get_permalink($pageChild->ID); ?>" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
<?php endforeach; endif; ?>

<?php }genesis();

谢谢你。

4

1 回答 1

0

错误在于您的get_results()论点。

首先分配post->ID给一个变量,然后get_results()像这样使用它:

$parent = $post->ID;
$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>

此外,我不确定您是否可以使用menu_order以及您使用'page'的方式,请查看文档如何获取这些。

于 2013-09-21T14:43:20.190 回答