Php 我对loop有意见
在我的代码中,我代表category id获取数据。但问题是,Php 我对loop有意见,php,wordpress,Php,Wordpress,在我的代码中,我代表category id获取数据。但问题是,为了获得每个term->term\u id,最后关闭foreach //loop the names of the slugs for the portfolio_categories $terms = get_terms(array('taxonomy' => 'portfolio_categories', 'hide_empty' => false, 'parent' => 0, 'orderby' =>
为了获得每个term->term\u id,最后关闭foreach
//loop the names of the slugs for the portfolio_categories
$terms = get_terms(array('taxonomy' => 'portfolio_categories', 'hide_empty' => false, 'parent' => 0, 'orderby' => 'date', 'order' => 'DESC'));
foreach ($terms as $term) {
$slug = $term->slug;
$term_id = $term->term_id;
$args = array(
'post_type' => 'Portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_categories',
'terms' => $slug,
'field' => 'slug',
)
),
'orderby' => 'ID',
'order' => 'DESC',
'posts_per_page' => -1
);
//}//Instead closing of here
?>
<?php
$posts_query = new WP_Query($args);
if (have_posts()) :
?>
<div id="<?php echo $term_id = $term->term_id; ?>" class="tabcontent">
<?php while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php echo '<div class="col-1-3">'; ?>
<?php echo $term_id = $term->term_id; ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "size"); ?>
<div class="wrap-col" >
<a class="fancybox" href="<?php echo $thumbnail[0]; ?>" data-fancybox-group= gallery>
<img src="<?php echo $thumbnail[0]; ?>"></a> </div>
</div>
<?php echo '</div>'; ?>
<?php
endwhile;
endif;
}//Close foreach here
?>
</div>
//循环公文包类别的slug名称
$terms=get_terms(数组('taxonomy'=>'portfolio_categories','hide_empty'=>false,'parent'=>0,'orderby'=>'date','order'=>'DESC');
foreach($terms作为$term){
$slug=$term->slug;
$term\u id=$term->term\u id;
$args=数组(
“post_type”=>“Portfolio”,
“tax_query”=>数组(
排列(
“分类法”=>“投资组合类别”,
“术语”=>$slug,
'字段'=>'段塞',
)
),
'orderby'=>'ID',
“订单”=>“描述”,
“每页帖子”=>-1
);
//}//而不是在这里关门
?>
大家好,我已经解决了这个问题。问题只是。div没有在for循环下管理。所以,如果您试图通过自定义类别获取自定义帖子,这就是答案
<?php
$taxonomy = 'portfolio_categories';
$args = array(
'hide_empty' => false
);
global $terms;
global $terms;
$terms = get_terms( 'portfolio_categories', $args );
?>
<div class="tab">
<?php $i = 0; ?>
<?php foreach ( $terms as $term ) { ?>
<?php $i++; ?>
<button class="tablinks" onclick="openCity(event, '<?php echo $term->term_id;?>')"
<?php if ($i == 1) { echo 'id="defaultOpen"'; } ?> ><?php echo $term->name;?></button>
<?php } ?>
</div>
<?php
//loop the names of the slugs for the portfolio_categories
$terms = get_terms(array('taxonomy' => 'portfolio_categories', 'hide_empty' => false, 'parent' => 0, 'orderby' => 'date', 'order' => 'DESC'));
foreach ($terms as $term) {
$slug = $term->slug;
$term_id = $term->term_id;
$args = array(
'post_type' => 'Portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_categories',
'terms' => $slug,
'field' => 'slug',
)
),
'orderby' => 'ID',
'order' => 'DESC',
'posts_per_page' => -1
);
//}//Instead closing of here
?>
<?php
$posts_query = new WP_Query($args);
if (have_posts()) :
?>
<div id="<?php echo $term_id = $term->term_id; ?>" class="tabcontent">
<?php while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php echo '<div class="col-1-3">'; ?>
<?php echo $term_id = $term->term_id; ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "size"); ?>
<div class="wrap-col" >
<a class="fancybox" href="<?php echo $thumbnail[0]; ?>" data-fancybox-group= gallery>
<img src="<?php echo $thumbnail[0]; ?>"></a> </div>
<?php echo '</div>'; ?>
<?php
endwhile;
endif;?>
</div>
<?php }//Close foreach here
?>
>
在这一行留出空间:
为什么要在每个循环中执行“echo$term\u id=$term->term\u id;”$术语_id已经在每个循环的开头分配,您不需要再重新分配多次。试试“echo$term_id”。narasimharaosp@我做了这个,然后什么也没显示出来。mean post不来narasimharaosp@如果此div处于循环中,则所有问题都将得到解决narasimharaosp@@narasimharaosp@@伙计们,我已经这样做了。问题是div和循环管理,我正在更新此answrere
<?php
$taxonomy = 'portfolio_categories';
$args = array(
'hide_empty' => false
);
global $terms;
global $terms;
$terms = get_terms( 'portfolio_categories', $args );
?>
<div class="tab">
<?php $i = 0; ?>
<?php foreach ( $terms as $term ) { ?>
<?php $i++; ?>
<button class="tablinks" onclick="openCity(event, '<?php echo $term->term_id;?>')"
<?php if ($i == 1) { echo 'id="defaultOpen"'; } ?> ><?php echo $term->name;?></button>
<?php } ?>
</div>
<?php
//loop the names of the slugs for the portfolio_categories
$terms = get_terms(array('taxonomy' => 'portfolio_categories', 'hide_empty' => false, 'parent' => 0, 'orderby' => 'date', 'order' => 'DESC'));
foreach ($terms as $term) {
$slug = $term->slug;
$term_id = $term->term_id;
$args = array(
'post_type' => 'Portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_categories',
'terms' => $slug,
'field' => 'slug',
)
),
'orderby' => 'ID',
'order' => 'DESC',
'posts_per_page' => -1
);
//}//Instead closing of here
?>
<?php
$posts_query = new WP_Query($args);
if (have_posts()) :
?>
<div id="<?php echo $term_id = $term->term_id; ?>" class="tabcontent">
<?php while ($posts_query->have_posts()) : $posts_query->the_post(); ?>
<?php echo '<div class="col-1-3">'; ?>
<?php echo $term_id = $term->term_id; ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "size"); ?>
<div class="wrap-col" >
<a class="fancybox" href="<?php echo $thumbnail[0]; ?>" data-fancybox-group= gallery>
<img src="<?php echo $thumbnail[0]; ?>"></a> </div>
<?php echo '</div>'; ?>
<?php
endwhile;
endif;?>
</div>
<?php }//Close foreach here
?>