WordPress.org

Ready to get started?Download WordPress

Forums

get_sidebar How Can I Make It Dynamic for is_single and is_category?? (9 posts)

  1. soleman
    Member
    Posted 5 years ago #

    I know this is asking a lot.... but is it possible to create an "if" (or whatever works..) statement that would allow me to use the Custom Field's key data to point to the sidebar?

    I have probably 100 categories and will have 10,000+ pages with 100 different sidebars and I sure don't want to keep adding to what I'm doing now which is:

    <?php if (is_single(7)) {include ('sidebars/sidebar5.php'); }
    else if (is_single(10)) {include ('sidebars/sidebar3.php'); }
    else {include ('sidebars/sidebar.php'); }
    ?>

    and

    <?php if (is_category(5)) {include ('sidebars/sidebar5.php'); }
    else if (is_category(3)) {include ('sidebars/sidebar3.php'); }
    else if (is_category(7)) {include ('sidebars/sidebar3.php'); }
    else {include ('sidebars/sidebar.php'); }
    ?>

  2. soleman
    Member
    Posted 5 years ago #

    I guess the only thing I need is an include with the post ID and the post ID's meta tag for the category.

    In each post I'll put a key named "sidebar" and the value will be the sidebar number.

    I just don't know how to write this.....

  3. soleman
    Member
    Posted 5 years ago #

    Or maybe an easier way would be to put a key as "side" and the value as "/sidebars/sidebarXXX.php" (whichever sidebar corresponds to that post).

    Would that work...? And can someone help with the syntax as I've tried 100 ways and I just can't get it. Started with something that didn't have a chance.... <?php {include ('<?php echo get_post_meta($post->ID, "side", $single = true); ?>'); }
    ?>

    and it didn't get any better from there....!

  4. soleman
    Member
    Posted 5 years ago #

    I can't think of any other angle to go at this. Just tough with my limited coding skills... like mad limited - !

  5. soleman
    Member
    Posted 5 years ago #

    Any ideas? Many thanks - !

  6. soleman
    Member
    Posted 5 years ago #

    Is this the correct forum?

  7. soleman
    Member
    Posted 5 years ago #

    Nobody?

  8. soleman
    Member
    Posted 5 years ago #

    I figured it out. Took mad long.....

  9. Justin Tadlock
    Member
    Posted 5 years ago #

    I'm not sure how you ended up doing this, but maybe something like this might work:

    $my_sidebar = get_post_custom_values("sidebar");
    get_sidebar($my_sidebar);

    This would be where your sidebars are named sidebar-1.php, sidebar-2.php, and so on.

Topic Closed

This topic has been closed to new replies.

About this Topic