2013-10-16 3 views
1

WordPress 루프를 사용하여 블로그 게시물을 태그별로 표시하는 페이지를 구현하려고합니다. 내가 겪어 본 문제는 태그를 페이지 제목으로 표시하도록 설정하는 것입니다. 지금까지 시도한 코드는 다음과 같습니다.WordPress Loop By 태그

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

PHP에서 작은 따옴표를 사용할 때 변수는 문자열에 삽입되지 않습니다.

따옴표를 사용하십시오 :

<?php query_posts("tag=$tag"); ?> 
여기

더 많은 정보 : What is the difference between single-quoted and double-quoted strings in PHP?

+0

감사합니다 다른 루프에서 $ 태그

<?php $tag=strtolower(the_title()); ?>

하고 나머지는 할당 한 것이다! 이제 실제로 게시물을 표시합니다. 올바른 것은 아니지만 이것이 페이지 제목이 아닌 루프와 관련이 있다고 생각합니다. 다시 한 번 감사드립니다! – salxander

1
$tag=strtolower(the_title()); 

get_the_title(); 반환이에 대한 링크를 참조하면서 출력

$tag=strtolower(get_the_title()); 

the_title(); 에코해야한다 more

+0

그리고 이것은 방금 마지막으로 언급 한 문제를 해결했습니다. 고맙습니다! – salxander

0

루프 전에 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 ;?>