出于某些原因,在Genesis框架中,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();
谢谢。
答案 0 :(得分: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'
的方式使用,请查看documentation如何获取这些内容。