Support » Plugins » List pages that belong to certain template

  • I am making a website that has 2 sections, and each uses a different template. I want the sidebar of each section to list all of the pages that use that particular template. I could manually include or exclude some pages, but then if I add a page I’ll have to change the code. Is there a way to tell it to list all pages belonging to a certain template?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this?

    $template_pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'mypagetemplate'");
    wp_list_pages('exclude=' .implode(",", $template_pages);

    of course replace mypagetemplate with your value.

    MichaelH

    (@michaelh)

    Oops, change the exclude to include. Sorry.

    $template_pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'mypagetemplate'");
    wp_list_pages('include=' .implode(",", $template_pages);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List pages that belong to certain template’ is closed to new replies.