WordPress中每个帖子的高级自定义字段

时间:2015-09-23 18:33:17

标签: php wordpress custom-post-type advanced-custom-fields

我正在使用高级自定义字段,以便使用qTranslate插件为每种语言显示不同的横幅图片。

<?php get_header(); ?>

<section id="linea">
            <?php if(qtrans_getLanguage()=='en') {
 ?>
                <img src="<?php the_field('banner')?>">
<?php }
else if(qtrans_getLanguage()=='es') {?>
                <img src="<?php the_field('banner_image_es')?>">
<?php }?>
        </section>
<section id="categoria1">
            <div class="pagewidth clearfix">
                    <div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">
                        <?php if(function_exists('bcn_display'))
                        {
                            bcn_display();
                        }?>
                    </div>
                    <h1 class="categoria-title"><span class="left"></span><b><?php single_term_title(); ?></b><span class="right"></span></h1>
            </div>
        </section>

        <section id="categoria2">
            <div class="pagewidth clearfix">

                <ul class="product-list">
                    <?php $my_query = new WP_Query(array('post_type' => 'productos','taxonomy'=>'categoria','term'=>'conformink-cunero-luxy','paged' => get_query_var('paged'))); ?>

                    <?php while ( $my_query->have_posts() ) : $my_query->the_post();?> 

                        <li>
                            <h5><a style="color: #f79646;"  href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>  
                            <a class="verdetalle" href="<?php the_permalink(); ?>"><?php if( qtranxf_getLanguage() == 'es' ){ ?>Ver detalle<?php }else { ?>See More<?php } ?></a>
                            <!-- <p><?php echo substr(get_the_excerpt(), 0,120); ?></p> -->
                            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>   
                        </li>

                    <?php
    endwhile;
    wp_pagenavi( array( 'query' => $my_query ) );?>
    <?php wp_reset_query(); ?>
                </ul>   
</div>
        </section>
<?php get_footer(); ?>

问题是它会在所有模板上只显示一个帖子的图像,尽管我已经将不同的图像分配给不同的类别。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

如果您希望横幅显示在每个帖子上,您必须在循环内移动该部分:

<section id="categoria2">
    <div class="pagewidth clearfix">

        <ul class="product-list">
            <?php 
            $my_query = new WP_Query(array('post_type' => 'productos','taxonomy'=>'categoria','term'=>'conformink-cunero-luxy','paged' => get_query_var('paged')));

            if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post();?> 

            <li>
                <section id="linea">
                    <?php if ( qtrans_getLanguage() == 'en' ) : ?>
                        <img src="<?php the_field('banner'); ?>">
                    <?php elseif ( qtrans_getLanguage() == 'es' ) : ?>
                        <img src="<?php the_field('banner_image_es'); ?>">
                    <?php endif; ?>
                </section>
                <h5><a style="color: #f79646;"  href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>  
                <a class="verdetalle" href="<?php the_permalink(); ?>"><?php if( qtranxf_getLanguage() == 'es' ){ ?>Ver detalle<?php }else { ?>See More<?php } ?></a>
                <!-- <p><?php echo substr(get_the_excerpt(), 0,120); ?></p> -->
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>   
            </li>
            <?php
            endwhile; endif;
            wp_pagenavi( array( 'query' => $my_query ) );
            wp_reset_query(); ?>
        </ul>   
    </div>
</section>