• Hello world and sorry for my bad and poor english.
    I am trying to makea query in a template, to extract all the sub pages of the current one. In addition to this, the extracted pages must have a particulare template.
    So, i have a page with (for example) 10 sub pages. 8 with a template A and the others with template B.
    I am trying to extract only the sub pages with template B.

    This is my code. But the “is_page_template()” conditional tag don’t work in this query. Seems to work only inside the main loop. What can i do?

    <?php
    $this_page_ID = get_the_ID();
    query_posts('post_type=page&post_parent='.$this_page_ID);
    if (have_posts()) :
    while (have_posts()) :
    the_post();
    if(is_page_template( 'templateB.php' ) ):
    the_title();
    endif;
    endwhile;
    endif;
    wp_reset_query();
    ?>

    Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • is_page_template will check for the page template of main page (current page), not subpages.

    Thread Starter Lorenzo Gasperoni

    (@tremisfero)

    Right, in fact i am using it inside a query_posts and before a wp_reset_query(). I was trying…
    This solution do’nt work, i can see it.
    Have you some other one to suggest? Thank you again!

    I am not sure if you can directly achive this using wp, but you can use an sql query for the same..

    select meta_value from $wpdb->posts WHERE post_id = $post_id AND meta_key = '_wp_page_template'

    Thread Starter Lorenzo Gasperoni

    (@tremisfero)

    Thank you. The query works but i had to change the table: not posts but postmeta.
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional template tag and sub pages extraction’ is closed to new replies.