我通过第一个循环获取第一个列表,其中category_name ="产品"。
而且__content我是这样的:
示例:
A
乙
C
d
我设置了一个名为$ product_name = get_the_content()/ * $ product_category =" A" * /
现在我想执行一个内部循环来获取嵌套列表,其中category_name =" $ product_category"。
这是我目前的代码:
<?php query_posts('category_name=Products'); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a>
<div style="padding:5px;background-color:black;margin-bottom:2px;">
<div style="display:inline-block;width:100px;vertical-align:middle;">
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail(); ?>
<?php } ?>
</div>
<div style="display:inline-block;height:100%;">
<a><?php the_title(); ?></a>
</div>
</div>
</a>
<?php $product_category = get_the_content(); ?>
<ul>
<?php query_posts('category_name=$product_category'); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</li>
<?php endwhile; ?>
<?wp_reset_query(); ?>
我的输出只显示第一项:
示例:
A
如何使用multi循环来获得如下结果:
示例:
A
产品1
产品2
乙
C
d
产品5
产品6
答案 0 :(得分:0)
您正在查看的是标准查询。您应该使用自定义帖子或自定义分类/自定义元来区分不同的类别。除非你使用php按名称排序。
WP_Query类允许您搜索数据库,并且可以在发送
之前将参数传递给类e.g。
$args=array(
'post_type'=> array('product1','product2'),
'tax_query' => array(
'relation'=>'AND',
array(
'taxonomy'=> 'producttypes',
'field'=> 'name',
'terms'=> array('onsale', fullprice)
)
array(
'taxonomy' => 'brands',
'field' => 'name',
'terms' => array( 'cocacola', 'pepsi', 'gatorade' ),
)
);
$query= new wp_query($args);
您可以使用查询变量执行加载,包括循环。对于多循环,只需创建类的新实例,例如$ query2 = new wp_query($ newargs);
所有这些的参考: http://codex.wordpress.org/Class_Reference/WP_Query