반응형
필요한 위치에 있지 않고 콘텐츠 상단에 쇼트코드가 표시됨
반품 문제인 것 같습니다.그래서 저는 내용을 나누었습니다.하나는 라는 함수로thelist다른 하나는 실제 기능을 되돌리는 것입니다.질문에 이어 코드가 표시된다.
내용이 나머지 내용보다 먼저 표시되는 것을 제외하고 실제 단축코드는 작동합니다.제가 생각하기에now_include_postreturn은 복구되지만 복구되지 않습니다.누구 도와줄 사람?
function thelist() {
if (have_posts()) : while (have_posts()) : the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('thumb'); ?>>
<a href="<?php the_permalink() ?>" class="thumb-link">
<?php
if (!post_password_required()) {
if (has_post_thumbnail()) {
the_post_thumbnail();
}
} else {
?>
<img src="<?php bloginfo('template_url') ?>/img/locked.png" />
<?php } ?>
</a>
<h2>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
</div>
<?php /* end post */ ?>
<?php
endwhile;
endif;
wp_reset_query();
}
?>
<?php
function now_include_post($atts) {
$thepostid = intval($atts[id]);
query_posts("p=$thepostid");
$output .= thelist();
return $output;
}
PHP를 이스케이프할 때 그 자리에서 출력하지 않고 모든 텍스트를 반환해야 합니다.
theslist() 함수 시작 시 출력 버퍼를 시작합니다.
ob_start();
마지막으로 이 버퍼를 닫고 내용을 반환한다.
return ob_get_clean();
WP 쇼트 코드의 경우는, 그 내용을 곧바로 에코 하는 것이 아니라, 그 내용을 되돌립니다.
언급URL : https://stackoverflow.com/questions/10406673/shortcode-coming-out-at-the-top-of-content-rather-than-in-place-where-i-require
반응형
'sourcecode' 카테고리의 다른 글
| JObject를 사전으로 변환합니다. 가능합니까? (0) | 2023.02.07 |
|---|---|
| Word press - get_results() - 실패 또는 비어 있는지 확인하는 방법 (0) | 2023.02.07 |
| WordPress에서 CloudConvert API 사용 (0) | 2023.02.07 |
| 라인 항목당 WooCommerce 쿠폰 코드 (0) | 2023.02.07 |
| wordpress enqueue 스크립트 문제("$가 정의되지 않음") (0) | 2023.02.07 |