• Does anybody have a piece of code for the WordPress 2.6 release that, when a page is brought up, it will list the links of all the other pages that use that same theme automatically? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Technically, Pages don’t use Themes, but you can specify that a Page use a specific Template within the framework of the currently active Theme.

    Are you wanting to display all Pages that use the same Page Template as the currently displayed Page?

    Thread Starter kev_120

    (@kev_120)

    Yes, sorry for the incorrect vocabulary usage!

    Thread Starter kev_120

    (@kev_120)

    What I meant to say was:

    “Does anybody have a piece of code for the WordPress 2.6 release that, when a page is brought up, it will list the links of all the other pages that use that same TEMPLATE automatically? Thanks!”

    This code in a Page Template should work:

    <?php
    $meta_key = '_wp_page_template';
    $template = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %d AND post_id = %s", $meta_key, $post->ID) );
    $template_pages = $wpdb->get_col( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %d AND meta_value = %s", $meta_key, $template) );
    wp_list_pages('include=' .implode(",", $template_pages));
    ?>

    How about if you want to list all pages that were created by the Page Template named ‘programs’?

    Thread Starter kev_120

    (@kev_120)

    For a page template called ‘programs’ it would be:

    <?php
    $meta_key = ‘_wp_page_template’;
    $template = ‘programs.php’;
    $template_pages = $wpdb->get_col( $wpdb->prepare(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s”, $meta_key, $template) );
    wp_list_pages(‘include=’ .implode(“,”, $template_pages));
    ?>

    Thanks Michael!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Automatically List All Pages of the Same Theme’ is closed to new replies.