我正在尝试实现一个使用 WordPress 循环按标签显示博客文章的页面。我遇到的问题是将标签设置为显示为页面标题。这是我迄今为止尝试过的代码。
<?php query_posts('tag=aetna'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="page-content ">
<?php the_content() ;?>
</div>
<?php endwhile; endif ;?>
这段代码工作得很好。但是,当我尝试将标签分配给页面标题时,它不起作用。这是我为此尝试过的代码。我是 PHP 新手,所以我希望这只是一个愚蠢的语法问题。
<?php $tag=strtolower(the_title()); ?>
<?php query_posts('tag=$tag'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="page-content ">
<?php the_content() ;?>
</div>
<?php endwhile; endif ;?>
非常感谢您为我提供的任何帮助。谢谢!
最佳答案
在 PHP 中使用单引号时,变量不会插入到字符串中。
尝试使用双引号:
<?php query_posts("tag=$tag"); ?>
更多信息请点击这里: What is the difference between single-quoted and double-quoted strings in PHP?
关于php - WordPress 按标签循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410012/