source

투고 대신 페이지에 워드프레스 LOUP를 사용하시겠습니까?

factcode 2023. 2. 9. 22:49
반응형

투고 대신 페이지에 워드프레스 LOUP를 사용하시겠습니까?

Wordpress에서 THE LOUP를 사용하여 투고 대신 페이지를 로드할 수 있는 방법이 있습니까?

일련의 자 페이지를 쿼리하고 그 위에서 THE LOUP 함수 호출을 사용할 수 있으면 좋겠습니다.the_permalink()그리고.the_title().

방법이 있을까요?에서는 아무것도 못 봤어요.query_posts()문서를 참조해 주세요.

네, 그럴 수도 있어요.새 WP_Query 개체를 만들 수 있습니다.다음과 같은 작업을 수행합니다.

query_posts(array('showposts' => <number_of_pages_to_show>, 'post_parent' => <ID of the parent page>, 'post_type' => 'page'));

while (have_posts()) { the_post();
    /* Do whatever you want to do for every page... */
}

wp_reset_query();  // Restore global post data

추가:query_posts에 사용할 수 있는 파라미터는 그 밖에도 많이 있습니다.유감스럽게도 전부는 아닙니다.http://codex.wordpress.org/Template_Tags/query_posts에 기재되어 있습니다.적어도post_parent더 중요한 것은 여기에 기재되어 있지 않습니다.나는 의 출처를 파헤쳤다../wp-include/query.php알아내기 위해서요.

이 질문의 나이를 고려해서 나는 그것을 우연히 발견하는 모든 사람에게 최신의 답을 제공하고 싶었다.

query_posts는 피하는 것이 좋습니다.다음은 제가 선호하는 대안입니다.

$child_pages = new WP_Query( array(
    'post_type'      => 'page', // set the post type to page
    'posts_per_page' => 10, // number of posts (pages) to show
    'post_parent'    => <ID of the parent page>, // enter the post ID of the parent page
    'no_found_rows'  => true, // no pagination necessary so improve efficiency of loop
) );

if ( $child_pages->have_posts() ) : while ( $child_pages->have_posts() ) : $child_pages->the_post();
    // Do whatever you want to do for every page. the_title(), the_permalink(), etc...
endwhile; endif;  

wp_reset_postdata();

다른 방법으로는 pre_get_posts 필터를 사용하는 방법이 있는데, 이는 프라이머리 루프를 변경해야 할 경우에만 해당됩니다.위의 예는 세컨더리 루프로 사용하는 것이 좋습니다.

자세한 것은, http://codex.wordpress.org/Class_Reference/WP_Query 를 참조해 주세요.

언급URL : https://stackoverflow.com/questions/196505/using-wordpress-loop-with-pages-instead-of-posts

반응형