, PHP

2012-01-25 2 views
1

I가 특정 태그로부터 랜덤 게시물을 생성하는 코드 여기, PHP

global $post; 
$postid = $post->ID; 
$args = array(
'orderby' => 'rand', 
'showposts' => 10, 
'tag' => 'ABC',    
'post__not_in' => array($postid) 
); 
query_posts($args); 
echo '<ul>'; 
while (have_posts()) : the_post(); 
echo '<li><a href="'.get_permalink().'" title="'.the_title('','',false).'">'.the_title('','',false).'</a></li>'; 
endwhile; 
echo '</ul>'; 

나 변수에 ABC를 저장할 때 태그가 'ABC'이지만,

그렇게 이유
$tagABC = 'ABC'; 

후이 방법을 작동하지 않습니다

global $post; 
$postid = $post->ID; 
$args = array(
'orderby' => 'rand', 
'showposts' => 10, 
'tag' => $tagABC,    
'post__not_in' => array($postid) 
); 
query_posts($args); 
echo '<ul>'; 
while (have_posts()) : the_post(); 
echo '<li><a href="'.get_permalink().'" title="'.the_title('','',false).'">'.the_title('','',false).'</a></li>'; 
endwhile; 
echo '</ul>'; 

여기에 변수 전화, 누군가가 설명 할 수 있을까?

답변

1

동일한 변수 이름을 사용하고 있습니까? 주의 다음은 예상대로 작동하는지 :

$tagABC = 'ABC'; 

$args = array(
'orderby' => 'rand', 
'showposts' => 10, 
'tag' => 'ABC',    
'post__not_in' => array(3) 
); 

$args2 = array(
'orderby' => 'rand', 
'showposts' => 10, 
'tag' => $tagABC,    
'post__not_in' => array(3) 
); 

var_dump($args2); 
var_dump($args); 

다음과 같은 출력이 주어진다 :

array(4) { 
    ["orderby"]=> 
    string(4) "rand" 
    ["showposts"]=> 
    int(10) 
    ["tag"]=> 
    string(3) "ABC" 
    ["post__not_in"]=> 
    array(1) { 
    [0]=> 
    int(3) 
    } 
} 
array(4) { 
    ["orderby"]=> 
    string(4) "rand" 
    ["showposts"]=> 
    int(10) 
    ["tag"]=> 
    string(3) "ABC" 
    ["post__not_in"]=> 
    array(1) { 
    [0]=> 
    int(3) 
    } 
} 

당신은 배열을 볼 수 $args$args2는 같은 값을 가지고 그 의미 배열이 그 변수 나 문자열을 사용하면 함수에 전달되는 값은 완전히 동일합니다.

+0

나는 다음 오류를 찾아 :) :) 문제가 거기에 없었습니다. –