WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] calling template sidebar (7 posts)

  1. lmann
    Member
    Posted 8 years ago #

    Heres the issue:

    I have two primary or top level static links, one called Articles and the second called Clients. Both of these will link to there own unique page template. The page template for Articles will call a unique sidebar specific to Articles. The page template for Clients will call a unique sidebar specific to Clients

    My question is this: I would like the Articles sidebar to only list pages that have been assigned to the Articles page template. I would like the Clients sidebar to only list pages that have been assigned to the Clients page template. Is this possible?

  2. illudium
    Member
    Posted 8 years ago #

    yep, use conditional tags.
    http://codex.wordpress.org/Conditional_Tags

    example:
    <?php if (is_page('4')) {
    wp_list_pages('exclude=1,2,3'); } ?>

    Edit: Actually if you're using unique sidebars to those pages, skip the is_page conditional tags and just use the exclude= in wp_list_pages.

  3. lmann
    Member
    Posted 8 years ago #

    Thanks -

    but will your example automatically update the sidebar unique to the specific template page. Basically, will I need to go into the php code for a specific sidebar to exclude certain pages everytime I create a new page.

    A work around for this is creating multiple authors and then assigning authors to a page, this way only pages who are written by a certain author will appear in a particular sidebar. I would like to apply the same thing to page templates. Basically, whenever I create a page, I assign it to a specific page template. The unique sidebar associated with that specific template will then be automatically updated. Thanks for your help

  4. Kafkaesqui

    Posted 8 years ago #

    Don't know if you have the skill to build on it (or around your own needs), but I've previously coded a solution for excluding Pages based on the Page template in use:

    http://wordpress.org/support/topic/57061#post-309307

  5. lmann
    Member
    Posted 8 years ago #

    Thats great - thanks!

  6. lmann
    Member
    Posted 8 years ago #

    How would it work if I wanted to exclude multiple templates, for example: clients.php and articles.php?

    <?php
    $template = 'clients.php';

    $Pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = '$template'");
    foreach($Pages as $Page) {
    $exclude_Pages .= $Page . ',';
    }
    wp_list_pages("exclude=$exclude_Pages&title_li=");
    ?>

  7. lmann
    Member
    Posted 8 years ago #

    For anyone who is interested in having only specific pages show on a unique sidebar in a unique page template, you can use the code above. If you want to have multiple template exclusions the code is below:

    <?php
    $template = 'clients.php'; //name of custom page template
    $template2 = 'photo.php'; //name of 2nd custom page temp

    $Pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = '$template'");
    foreach($Pages as $Page) {
    $exclude_Pages .= $Page . ',';
    }
    $Pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = '$template2'");
    foreach($Pages as $Page) {
    $exclude_Pages .= $Page . ',';
    }
    wp_list_pages("exclude=$exclude_Pages&title_li=");
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.