의 상단에 나는 페이지에 사용자 정의 게시물을 표시하기 위해 사용하고있는 다음과 같은 단축 코드가있다 :워드 프레스 단축 코드는 항상 페이지
add_shortcode('page-section', 'page_section_shortcode');
function page_section_shortcode($atts) {
global $post;
$post_slug=$post->post_name;
$a = shortcode_atts(array(
'post-name' => 'qwerty',
'bg-color' => 'white'
), $atts);
$post_slug=$post->post_name;
$post_name = $a['post-name'];
$query = new WP_Query(array(
'post_type' => 'page_section',
'name' => $post_name,
));
if ($query->have_posts()) { ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div style="background-color: <?php echo $a['bg-color']; ?>" id="<?php global $post; $post_slug=$post->post_name; echo $post_slug; ?>" class="page-section">
<div class="row">
<?php the_content(); ?>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}
모든 것은 내가, 내가 내용을 설정할 수 있습니다 원하는 방식으로 작업한다 내 사용자 정의 게시물에 짧은 코드를 사용하여 해당 내용을 페이지로 가져옵니다.
짧은 코드로 가져온 콘텐츠는 항상 페이지의 맨 위에 있습니다. 한 행에 여러 개의 단축 코드를 사용하면 주문은 유지되지만 페이지의 다른 모든 내용은 하단에 표시됩니다 (모든 단축 코드 내용 아래에 있음).
나는 '에코'를 다른 stackoverflow 게시물에서 제안 된 것처럼 제거하려고했지만 내가 잘못하고있는 것을 발견하지 못하는 것 같습니다.
ob_start()를 시작하지 않았습니다. 본문에서 시작 shortcode 함수의 맨 위에. – user5200704