elianab
Member
Posted 4 years ago #
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?
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.
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);