Forums

Best Method - Dependent Sidebar by Post (7 posts)

  1. mfshearer72
    Member
    Posted 3 years ago #

    Hi,

    I need to have dependent sidebars per group of posts. I.E. I have posts 21-40 that need one sidebar and 41-60 that need another. The best way I've figured out to do this is by this code example:

    if (is_single(27))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(28))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(29))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(30))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(38))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(39))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(40))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(41))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(42))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(43))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(44))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(45))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(46))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(47))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(48))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    else ; ?>

    But multiple that by 5 times the number of posts and it is way to much processing. Also, should I add breaks between each of these?

    If you can let me know your recommendations for optimizing this kind of code.

    Kindly,
    Michael

  2. moshu
    Member
    Posted 3 years ago #

    Reading the Docs always helps:
    Conditional_Tags#A_Single_Post_Page

  3. mfshearer72
    Member
    Posted 3 years ago #

    No offense but reading my full post might help, too. If you had, you'd see I already apply conditional tags using is_single.

    What I wanted to know was is there a more efficient way instead of writing hundreds of elseif statements...e.g. grouping posts. What would be ideal if I could write is_single(1,2,3,4,5)...

  4. moshu
    Member
    Posted 3 years ago #

    And that's exactly what the LAST example shows you how to do it with "array".
    I do take offense when people don't read it...

  5. mfshearer72
    Member
    Posted 3 years ago #

    Thank you and I apologize sincerely for missing the part you were referencing to.

  6. mfshearer72
    Member
    Posted 3 years ago #

    And for future reference to people reading this post, that long string of code I posted above is now easily translated into this:

    <?php
    if (is_single(array(27,28,29,30,38,39,40,41,42,43,44,45,46,47,48)))
    {include(TEMPLATEPATH."/rookiebottombar.php");}
    elseif (is_single(array(49,50,51,52,54,55,56,57,58,59,60,61,62)))
    {include(TEMPLATEPATH."/veteranbottombar.php");}
    elseif (is_single(array(63,64,65,66,67,68,69,70,71,72,73)))
    {include(TEMPLATEPATH."/allstarbottombar.php");}
    else ; ?>
  7. moshu
    Member
    Posted 3 years ago #

    Thank you for posting the final solution!

Topic Closed

This topic has been closed to new replies.

About this Topic