如果图像存在,我该如何才显示图像?

时间:2013-03-11 16:32:21

标签: php wordpress-theming wordpress

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

目标是仅在 feature-image-3存在时才显示所有子页面的精选图像3(我使用此plugin来显示多个精选图像)。我的方法如下

  1. 获取当前页面ID
  2. 使用当前页面ID查询子页面
  3. 如果有子页面设置每个子页面的发布数据
  4. 检查子页面是否有feature-image-3
  5. 如果子页面有feature_image-3 显示:如果不是查询下一篇文章
  6. 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 );
    

    }

0 个答案:

没有答案