2015-01-05 7 views
0

나는 약간의 검색을했기 때문에 잘못된 것을 검색하고있을 수도 있습니다. 내 function.php 파일에서 WordPress의 함수를 실행하고 반환 된 배열을 변수에 할당하려고합니다.Wordpress functions

함수를 실행할 때 변수에 할당하지 않고 반환 된 데이터를 에코합니다.

저는 이것이 Wordpress 일이라고 가정합니다. functions.php

function get_portfolioBlock() { 
$portfolio_query = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 1, 'name' => 'test1')); 
if ($portfolio_query->have_posts()) { 
    while ($portfolio_query->have_posts()) { 

     $portfolio_query->the_post(); 
     $portfolio_block = array('title' => the_title(), 'excerpt' => the_excerpt()); 
    } 
    return $portfolio_block; 
} else { 
    return 'error'; 
} 

}에서

코드

내 템플릿 파일의 코드

<?php $portfolio = get_portfolioBlock(); ?> 

페이지가로드 자동 변수를 지정하지 않고 페이지에 데이터를로드 나를 위해 다른 사람을 사용하십시오.

+3

WP 기능을 사용 했어야 때문에 함수이었다 아웃 반향 이유'the_whatever()을 '출력 할 것이다. 'get_the_whatever()'는 출력하는 대신 RETURN을 반환합니다. –

+0

get_the_get_portfolioBlock을 넣으면 정의되지 않은 함수 오류가 발생합니다. get_the를 어디에 둘 필요가 있습니까? 함수 이름으로? –

+0

번호. '$ portfolio_query-> get_the_post()' –

답변

0

제럴드 감사합니다!

I가 the_title 및 the_excerpt 할당 될 때 난

get_the_title() and get_the_excerpt()