• 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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Reading the Docs always helps:
    Conditional_Tags#A_Single_Post_Page

    Thread Starter mfshearer72

    (@mfshearer72)

    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)…

    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…

    Thread Starter mfshearer72

    (@mfshearer72)

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

    Thread Starter mfshearer72

    (@mfshearer72)

    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 ; ?>

    Thank you for posting the final solution!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Best Method – Dependent Sidebar by Post’ is closed to new replies.