2013-10-16 62 views
1

我想实现一个页面,显示使用WordPress循环标记的博客文章。我遇到的问题是将标记设置为显示为页面标题。这是迄今为止我尝试过的代码。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 ;?> 

任何帮助,你可以提供我非常感谢。谢谢!

回答

1
$tag=strtolower(the_title()); 

应该

$tag=strtolower(get_the_title()); 

the_title();回声而get_the_title();回报它是指用于链接输出更多

+0

这就解决了我在上次评论中提到的问题。谢谢! – salxander

0

您正在循环之前调用the_title()。 这是一个只能在循环内调用的函数。

如果你想使用该功能,您需要创建两个查询,一个是分配$标签

<?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 ;?>