【发布时间】:2015-09-23 18:33:17
【问题描述】:
我正在使用高级自定义字段,以便通过 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(); ?>
问题是它在所有模板上只显示一个帖子的图像,尽管我已经将不同的图像分配到不同的类别。
谁能帮忙?
【问题讨论】:
-
上面这段代码应该不是问题。在您的问题中,您提到了类别。您的代码与类别无关。
-
我有不同类别的不同产品,并为此帖子类型分配了两个自定义字段,我如何根据类别在每个页面上获取横幅图像?现在它在所有页面上显示相同的图像。
-
您上面的代码 sn-p 不必对类别做任何事情。这段代码在哪里?在你的
index.php、single.php、category.php、...? -
感谢您的回复我的代码在这个文件“taxonomy-categoria-organica-bebe.php”中,我的类别名称是“organica-bebe”。
-
你检查过这个模板是否真的被使用过吗?我认为应该是
category-organica-bebe.php(根据codex.wordpress.org/Category_Templates)。帖子或类别是否附加了不同的标志?上面的代码是否在循环中?您应该从模板中添加更多代码以获得答案。
标签: php wordpress custom-post-type advanced-custom-fields