【发布时间】:2014-02-22 19:42:53
【问题描述】:
我已经编写了一些基本的 PHP 来获取特定类别中任何帖子的永久链接和标题。这是为页脚编写的,效果很好。
我现在的问题是,当我尝试在 if 循环中使用相同的代码时,它会失败。
我应该做些什么不同的事情?
这是我的代码:
<?php if (in_category('training'))
{
<?php query_posts('category_name=training'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
}
elseif (in_category('club'))
{
<?php query_posts('category_name=club'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
}
else
{
echo "Nothing to show";
}
?>
【问题讨论】:
-
你能说出你遇到了什么错误吗?
-
不幸的是没有错误。循环下方的内容无法加载。
-
您是否尝试过在设置中使用 wp_debug true 来查看是否出现任何错误?或者,如果您在网络服务器错误日志中收到任何错误?
-
我没有。对不起,这一切对我来说还是很新的。解析错误:语法错误,第 4 行 /Applications/MAMP/htdocs/thames_new/wp-content/themes/expound/side-bar.php 中的意外“
标签: php wordpress if-statement while-loop