태그 보관물: pages

pages

WP_Query를 사용한 페이지 템플릿 쿼리 함수가있는 페이지

WP_Query게시물 객체를 반환 하는 특정 페이지 템플릿 이나 함수가있는 페이지 만 쿼리 하고 싶지만 공식 코덱에서 해당 정보를 찾을 수 없습니다.



답변

이것을 시도하십시오 … 템플릿 이름이 ‘my_template.php’라고 가정하면,

$query = new WP_Query(
    array(
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
        'meta_value' => 'my_template.php'
    )
);
//Down goes the loop...

get_posts 를 사용 하거나 쿼리 게시물 을 수정 하여 작업을 완료 할 수도 있습니다 . 이 두 함수는 WP_Query 와 동일한 매개 변수를 사용합니다 .


답변

틀린 예 : 워드 프레스 3 기준으로 다음과 비슷한 것이 필요합니다.

$args = array(
    'post_type'  => 'page', 
    'meta_query' => array( 
        array(
            'key'   => '_wp_page_template', 
            'value' => 'my_template.php'
        )
    )
);


답변

페이지 템플리트는 “_wp_page_template”키와 함께 메타 값으로 저장됩니다.

따라서 메타 쿼리 매개 변수에서 해당 키를 사용하면됩니다. 예를 들어

http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query#Query_based_on_Custom_Field_and_Sorted_by_Value를 참조하십시오 .


http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters


답변

누군가가 잘못 게시물을 올리지 않으면 템플릿 이름이 잘못되었을 수 있습니다. PHP 파일 이름과 템플릿 이름을 시도했지만 작동하지 않았습니다. 그런 다음 페이지 편집기에서 템플릿을 선택하는 템플릿 선택 상자를 검사하기로 결정했습니다. 나는 이것을 찾았다:

<option value="templates-map/component-tutorial-1.php" 
 selected="selected">Tutorial -1</option>

나는 그것을 사용 templates-map/component-tutorial-1.php했다.


답변

다른 폴더 안에 템플릿이있는 경우 :

$args = array(
    'post_type' => 'page', //it is a Page right?
    'post_status' => 'publish',   
    'meta_query' => array(
        array(
            'key' => '_wp_page_template',
            'value' => 'page-templates/template-name.php', // folder + template name as stored in the dB
        )
    )
);


답변