내가 여기에 간단한 WP_Query 인스턴스를 사용하고, 다음 코드를 사용합니다 :
<?php
// Set the WP_Query arguments
$args = array(
'post_type' => 'page',
// You need to change this to match your post IDs
'post__in' => array(10, 20, 30),
'order_by' => 'post__in',
'order' => 'DESC' // Might need to change this to "ASC"...
);
// Create the page section query
$page_section_query = new WP_Query($args);
// Simple check...
if($page_section_query->have_posts()) :
while($page_section_query->have_posts()) :
$page_section_query->the_post();
global $post;
// Print out the section!
?>
<section id="<?php echo esc_attr($post->post_name) ?>" <?php post_class(array(esc_attr('page-section-' . $post->post_name))); ?>>
<!-- contents of the page section -->
</section>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
을
간단하고 효과적인 1 개의 쿼리 만 있으면됩니다. 더 많은 섹션을 원한다면 더 많은 게시물 ID를 계속 추가하십시오.
게시 ID를 주문 매개 변수로 사용하지 않으려면 대신 menu_order
을 사용할 수 있습니다. post__in
매개 변수를 사용하지 않으려면 모든 페이지를 페이지 상위 항목에 추가하고 상위 게시물 ID를 사용하여 섹션의 모든 페이지 하위 항목을 가져올 수 있습니다. 이렇게하면 솔루션이 모듈화됩니다.
WP_Query에 대한 자세한 내용은 여기를 참조하십시오. https://codex.wordpress.org/Class_Reference/
나를 도와 주셔서 감사합니다. 내 섹션에 다른 CSS가 있다면? @MrZiggyStardust – user3242861
section 요소 내에서 post_class() 함수를 사용하십시오. https://codex.wordpress.org/Function_Reference/post_class - 다르게 생성 된 CSS 클래스의 모든 섹션 스타일을 지정합니다. – MrZiggyStardust