2014-04-28 4 views
0

페이지 ID를 가져 와서 해당 페이지의 미리보기를 반환하는 플러그인을 작성하려고합니다. 여기에 내 코드입니다 :<!--more-->은 WordPress 콘텐츠가 표시 될 때 무시됩니다.

function page_preview($atts,$pageid = null) { 
extract(shortcode_atts(array(
"pageid" => '0' 
), $atts)); 
$the_query = new WP_Query('page_id=' . $pageid . ''); 
global $more;  
$more = 0; 
if ($the_query->have_posts()) { 

while ($the_query->have_posts()) { 
    $the_query->the_post(); 
    $title=get_the_title(); 
    $thumbnail=get_the_post_thumbnail($pageid, 'preview'); 
    $content=get_the_content(); 
} 
} 
return '<div class="callout">' . 
'<h4>' . 
$title . 
'</h4>' . 
$thumbnail . 
$content . '<a href="' . 
get_the_permalink($pageid) . 
'">Continue reading</a></div>'; 
} 
add_shortcode('pagepreview', 'page_preview'); 

그것은 같은 wpadmin 편집기에 호출되는 그래서 : [pagepreview 페이지 id = 11] [pagepreview 페이지 id = 13] [pagepreview 페이지 id = 8054] 즉, 그에 대한 페이지 미리보기를 표시 할 각 페이지 ID.

"more"가 작동하지 않습니다.

global $more;  
$more = 0; 

은 일반적으로이 문제를 해결하지만 내 경우에는 해당되지 않습니다. 아무도 내가 "잘못? 감사를하고있어 무엇을 볼 수 있습니다.

답변

1

$content=get_the_content();

the_content() 필터를 적용하지 않기 때문에 당신은 전체 콘텐츠를 얻고, 그리고 $more=0 안쪽 $the_query->the_post(); 후 행에 있어야합니다 . while 루프는이에 while 루프를 변경합니다

while ($the_query->have_posts()) { 
    $the_query->the_post(); 
    $more=0; 
    $title=get_the_title(); 
    $thumbnail=get_the_post_thumbnail($pageid, 'preview'); 
    $content = apply_filters('the_content', get_the_content()); 
    $content = str_replace(']]>', ']]&gt;', $content); 
} 

가 어디 소스에 워드 프레스 코덱스에 get_the_contentread more in pages를 참조하십시오 이거.

+0

감사합니다. 이것을 시도했지만 여전히 작동하지 않습니다. 어디에서나 $ more = 0을 넣었습니다. 아직 성공하지 못했습니다 ... –

+0

플러그인으로부터 어떤 결과를 얻고 있습니까? 게시물의 전체 내용 (위 또는 아래 태그) 또는 다른 것을 얻고 있습니까? – vvanasten

+0

위와 아래의 게시물 전체 출력 받기. –

관련 문제