您好,我有一个归档帖子页面,在那里我动态地拉入帖子,然后按年份然后按月排序。我正在尝试添加引导手风琴效果,将一年中的几个月隐藏起来,直到单击为止。
我正在使用echo$year\\u current为每年生成一个唯一的id。但出于某种原因,它仍然不起作用。只是第一年,其他一切都隐藏了起来。我在它上面有一个计数器来应用\'。“在”类中
<?php $c = 0; ?>
<div id="collapse-<?php echo $year_current; ?>" class="panel-collapse collapse <?php if( $c == 1 ) echo \'in\'; ?>" role="tabpanel" aria-labelledby="heading-<?php echo $year_current; ?>">
任何帮助都将不胜感激!这是我的代码:
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="mid_yellow">
<p>Archives</p>
</div>
<div id="mid_yellow">
</div>
<p ></p>
<?php $c = 0; ?>
<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = \'publish\' and post_date <= now( ) and post_type = \'post\' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year; $c++;
if ($year_current != $year_prev)
{
if($year_current != date(\'Y\'))
{
?>
</ul>
<?php
}
?>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-<?php echo $year_current; ?>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" aria-controls="collapse-<?php echo $year_current; ?>" href="#collapse-<?php echo $year_current; ?>/"><?php echo $month->year; ?></a>
</h4>
</div>
<div id="collapse-<?php echo $year_current; ?>" class="panel-collapse collapse <?php if( $c == 1 ) echo \'in\'; ?>" role="tabpanel" aria-labelledby="heading-<?php echo $year_current; ?>">
<ul class=\'list-group\'>
<?php
}
?>
<li class=\'list-group-item\'>
<a href="<?php bloginfo(\'url\') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>"><span class="archive-month"><?php echo date_i18n("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?></span></a>
</li>
<?php
$year_prev = $year_current;
endforeach;
?>
</ul>
</div>
</div>
</div>
<?php get_footer(); ?>