我对php很新,并且在弄清楚我做错了什么时遇到了一些麻烦。出于某种原因,kd_mfi_the_featured_image( 'featured-image-3', 'post' );
不存在(即使它上传并且在单词按管理面板中看起来很好),因此它不是= true并且不会显示。
目标是仅在 feature-image-3存在时才显示所有子页面的精选图像3(我使用此plugin来显示多个精选图像)。我的方法如下
customPage.php中的代码
<?php if ( have_posts() ) { /* Query and display the parent. */
while ( have_posts() ) {
the_post();
the_content();
$thispage=$post->ID;
}
}?&gt;
<?php $childpages = query_posts('post_type=page&post_parent='.$thispage);
if($childpages) /* display the children content */
foreach ($childpages as $post) :
setup_postdata($post);
if (kd_mfi_the_featured_image( 'featured-image-3', 'post' )) {
kd_mfi_the_featured_image( 'featured-image-3', 'post' );
the_post_thumbnail();
}
else {
$wp_query->next_post();
}
endforeach; ?>
Functions.php中的代码
if( class_exists( 'kdMultipleFeaturedImages' ) ) {
$args2 = array(
'id' => 'featured-image-2',
'post_type' => 'page', // Set this to post or page
'labels' => array(
'name' => 'Home Page Carousel',
'set' => 'Set Home Page Carousel',
'remove' => 'Remove Home Page Carousel',
'use' => 'Use as Home Page Carousel',
)
);
$args3 = array(
'id' => 'featured-image-3',
'post_type' => 'page', // Set this to post or page
'labels' => array(
'name' => 'Product Category Hero',
'set' => 'Set Product Category Hero',
'remove' => 'Remove Product Category Hero',
'use' => 'Use as Product Category Hero',
)
);
$args4 = array(
'id' => 'featured-image-4',
'post_type' => 'page', // Set this to post or page
'labels' => array(
'name' => 'Product Category Featured',
'set' => 'Set Product Category Featured',
'remove' => 'Remove Product Category Featured',
'use' => 'Use as Product Category Featured',
)
);
new kdMultipleFeaturedImages( $args2);
new kdMultipleFeaturedImages( $args3 );
new kdMultipleFeaturedImages( $args4 );
}