0

我创建了以下一个新的帖子元框:

// Big Artful Interiors Post Meta Box
if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(
        array(
            'label' => 'Big Artful Interiors',
            'id' => 'big-artful-interiors',
            'post_type' => 'post'
        )
    );
}

我想以全尺寸显示这个新的特色图片来代替我的网站主页本节 -> http://nimb.ws/PFxVej第一个特色图片。

现在,在主题 front-page.php 文件中使用以下代码显示帖子特色图像。

<?php
    $artful_int_options = array('artful_int_1', 'artful_int_2', 'artful_int_3');
    $artful_ints = array();
    foreach ( $artful_int_options as $artful_int_option ) {
        if ( !empty( ot_get_option( $artful_int_option ) ) ) {
            $artful_ints[] = ot_get_option( $artful_int_option );
        }
    }
    if ( !empty( $artful_ints ) ) {
        $args_art_ints =  array('post__in'=>$artful_ints,'posts_per_page'=>3,'orderby'=>'post__in');
        $query_art_ints = new WP_Query($args_art_ints);

        if ($query_art_ints->have_posts()) {
                ?>
                <div id="artful_interiors">
                    <h2>Artful Interiors</h2>
                    <div class="subheading">By Luxury Home and Design Show</div>
                    <div class="row" data-equal=">.columns">
                        <div class="columns small-12 medium-9"> 
                            <div class="row">
                                <?php while ( $query_art_ints->have_posts() ) : $query_art_ints->the_post(); ?>
                                    <div class="small-12 large-12 columns post">
                                        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                            <?php the_post_thumbnail('thevoux-single',array('itemprop'=>'image')); ?>
                                        </a>
                                        <div class="featured-title">
                                            <?php if( has_category() ) { ?>
                                                <aside class="post-meta cf">
                                                    <?php the_category(', '); ?>
                                                </aside>
                                            <?php } ?>
                                            <div class="row">
                                                <div class="columns medium-10"> 
                                                     <div class="post-title">
                                                        <a href="<?php the_permalink(); ?>"><?php the_title() ?></a>
                                                     </div> 
                                                </div>
                                                <div class="columns medium-2">
                                                    <figure class="post-gallery <?php do_action('thb_is_gallery'); ?>"></figure>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                <?php break; endwhile; ?>
                            </div>
                            <div class="row posts">
                                <?php while ( $query_art_ints->have_posts() ) : $query_art_ints->the_post(); ?>
                                    <div class="small-12 large-6 columns">
                                        <?php 
                                            set_query_var( 'disable_excerpts', 'true' );
                                            set_query_var( 'disable_author', 'true' );
                                            get_template_part( 'inc/templates/loop/style6' ); 
                                        ?>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>

                        <div id="second_q_block" class="columns medium-3 small-12 q_block">
                            <div class="sidebar-inner fixed-me">
                                <?php tol_ad('front_artful_interiors') ?>
                            </div>
                        </div>
                    </div>
                </div>
        <?php
            wp_reset_postdata();
        }
    } ?>

我已遵循插件说明https://github.com/voceconnect/multi-post-thumbnails/wiki但这在我的 front-page.php 文件中不起作用。

关于如何显示此自定义特色图像的任何想法?

谢谢。

4

1 回答 1

1

尝试这个:

<?php
$lead_article = ot_get_option('lead_article');
$thumb_id = MultiPostThumbnails::get_post_thumbnail_id( 'post', 'homepage-full-width', get_the_ID() );
if ($thumb_id) :
    $lead_article_img_horizontal = wp_get_attachment_image_src($thumb_id, "tol-horizontal");
    $lead_article_img_vertical = wp_get_attachment_image_src($thumb_id, "tol-vertical");
    $lead_article_img_horizontal_src = esc_url( $lead_article_img_horizontal[0]);
    $lead_article_img_vertical_src = esc_url( $lead_article_img_vertical[0]);
?>

<div id="lead-article" class="post featured-style10 post-header">

<div  data-interchange="[<?php echo $lead_article_img_horizontal_src ?>, landscape], [<?php echo $lead_article_img_vertical_src ?>, portrait]" class="parallax_bg skrollable skrollable-between" data-bottom-top="transform: translate3d(0px, -20%, 0px);" data-top-bottom="transform: translate3d(0px, 20%, 0px);" style="transform: translate3d(0px, 0.382158%, 0px);background-image: url(<?php echo $lead_article_img_horizontal_src ?>)"></div>

</div>

<?php endif; ?>
于 2018-02-19T14:19:24.897 回答