【发布时间】:2016-10-06 19:21:06
【问题描述】:
我正在尝试根据当前类别显示不同的样式。所以我正在尝试使用 if/else 来做到这一点。但是,当我加载页面时,什么都没有出现......
提前致谢。
<?php
if (have_posts()) : while (have_posts()) : the_post();
$current_section = single_cat_title();
if ($current_section == "music") {
?>
<li class="music_post"><a href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a></li>
<?php
}
elseif ($current_section == "blog")
{
?>
<li class="blog_post"><a href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a></li>
<?php
}
?>
<? endwhile;?>
<? endif; ?>
【问题讨论】:
-
你到底想做什么,会发生什么?您尝试了哪些方法,为什么不起作用?
-
$current_section 是音乐还是博客?将另一个 else 添加到默认值
-
我正在尝试为博客类别和音乐类别展示不同的风格。所以,我添加了 if/else,但没有任何反应......