0

我对 php 很陌生,并且在弄清楚我做错了什么时遇到了一些麻烦。由于某种原因kd_mfi_the_featured_image( 'featured-image-3', 'post' );不存在(即使它上传并且在 word press 管理面板中看起来很好)所以它不 = true 并且它不会显示。

目标是仅在 feature-image-3 存在时才显示所有子页面的features-image-3(我正在使用这个插件来拥有多个特色图像)。我的方法如下

  1. 获取当前页面ID
  2. 我们当前页面ID查询子页面
  3. 如果有子页面为每个子页面设置帖子数据
  4. 检查子页面是否有 feature-image-3
  5. 如果子页面有 features_image-3显示它:如果没有查询下一篇文章

customPage.php 中的代码

<?php if ( have_posts() ) {  /* Query and display the parent. */
while ( have_posts() ) {
the_post();
the_content();
$thispage=$post->ID;
}

} ?>

<?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 );

}

4

0 回答 0