• Resolved magicalwonders

    (@magicalwonders)


    Hello folks,

    I’m trying to get my theme to display a different sidebar on one page, and have tried the following code:

    <?php if (is_page(36)) {include (’sidebar2.php’); }
    else {include (’sidebar1.php’); }
    ?>

    Although the code parses without any error, none of the two sidebars appears on the page. You can see the result at this url: https://really-valid-info.com/blog/

    Can anyone help and advise why this is not working, or suggest an alternative method?

    Many thanks,

    Myles

Viewing 13 replies - 1 through 13 (of 13 total)
  • include(TEMPLATEPATH . '/sidebar1.php');

    Thread Starter magicalwonders

    (@magicalwonders)

    Hi, thanks for the response.

    I’ve been playing around with this a bit and have modified my code.
    I now have two sidebars called sidebar.php and sidebar2.php

    Have tried the following code without success –

    <?php get_header(); ?>
    
    <?php 
    
    if  (is_page('36'))  { 
    
    include(TEMPLATEPATH . '/sidebar2.php'); 
    
    } else { 
    
    get_sidebar();
    
    }	
    
    ?>

    My code for sidebar2 is as follows

    <div id="sidebar1" class="column">
    
    	<ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    	</div>
    
    	<div>
    
    	<h2>Archives</h2>
    
    				<?php wp_get_archives('type=monthly'); ?>
    
      <!-- end #sidebar2 --></div>

    I don’t seem to be able to get sidebar2 which shows the archive to display. I’ve tried (is_page(’36’) without the quotes around the number, but that doesn’t seem to work either!

    Not sure where I’m going wrong?

    Would be grateful for any advice.

    Myles

    Thread Starter magicalwonders

    (@magicalwonders)

    I’ve also tried using a conditional statement just in the one sidebar as follows:

    <?php
    if (is_page ('News')) { ;?>
    
    <div id="sidebar1" class="column">
    <ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    	</div>
    
    	<div>
    
    	<h2>Archives</h2>
    
    				<?php wp_get_archives('type=monthly'); ?></div>
    
    <?php } else { ?>
    <div id="sidebar1" class="column">
    <ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    
    <?php } ?>
    
      <!-- end #sidebar --></div>

    That doesn’t seem to have any affect either!

    Anyone got any ideas on why my code isn’t working?

    I just tested this, and it worked:

    <?php if ( is_page('36') ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar.php');?>
    <?php } ?>

    Hope it helps!

    Thread Starter magicalwonders

    (@magicalwonders)

    Hi buddha trance,

    Thanks for the help. I’ve tried that code, but it still doesn’t seem to display sidebar2.php for some reason. I can’t see where I’m going wrong.

    My index.php is as follows:

    <?php get_header(); ?>
    
    <?php if ( is_page('36') ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar.php');?>
    <?php } ?>
    
    <div id="mainContent" class="column">
        <?php if (have_posts()): ?><?php while(have_posts()):the_post(); ?>
    
    <div class="post" id="post-<?php the_id(); ?>">
    
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    	<div class="entry">
    
    		<?php the_content(); ?>
    
    		<p class="postmetadata">
    <?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
    				</p>
    
    	</div>
    
    </div>
    
    	<?php endwhile; ?>
    
    		<div class="navigation">
    		<?php posts_nav_link('','Previous page','Next page'); ?>
    		</div>
    
    	<?php else: ?>
    
    		<div class="post">
    			<h2><?php_e('not_found'); ?></h2>
    		</div>
                  <?php endif; ?>
    
    <!-- end #mainContent --></div>
    <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
    
    <?php get_footer(); ?>

    Code for sidebar.php is –

    <div id="sidebar1" class="column">
    <ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    
    <!-- end #sidebar --></div>

    And sidebar2.php is as follows –

    <div id="sidebar1" class="column">
    
    	<ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    	</div>
    
    	<div>
    
    	<h2>Archives</h2>
    
    			<?php wp_get_archives('type=monthly'); ?>
    
    <!-- end #sidebar2 --></div>

    When uploaded, only sidebar appears to be showing on the News page –
    https://really-valid-info.com/blog/?page_id=36

    I can’t see why this is not working?

    I am not sure if this makes a difference, but the way I tested it, was by editing sidebar.php, and not index.php

    Try this way:
    Keep index.php as it was originally, it will call for the sidebar the usual way <?php get_sidebar(); ?>

    Make a copy of sidebar.php, and rename it sidebar1.php

    Edit sidebar.php and just use that code, except that now you want to call sidebar1.php (instead of sidebar.php) and sidebar2.php

    <?php if ( is_page('36') ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar1.php');?>
    <?php } ?>

    The content of your sidebars is in sidebar1 and sidebar2, while sidebar.php has the conditional code (which I tested to work). See if it works that way.

    Thread Starter magicalwonders

    (@magicalwonders)

    This isn’t working for me for some reason.

    I’ve only got six templates currently in the theme. Index.php footer.php header.php sidebar.php sidebar1.php and sidebar2.php

    The index now shows <?php get_sidebar(); ?>
    sidebar.php code is –

    <?php if ( is_page('36') ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar1.php');?>
    <?php } ?>

    sidebar1.php code is –

    <div id="sidebar1" class="column">
    <ul id="navlist" class="backgroundbullet">
    
    	<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    
    	</ul>
    <!-- end #sidebar --></div>

    and sidebar2.php code is –

    <div id="sidebar1" class="column">
       <ul id="navlist" class="backgroundbullet">
        <?php wp_list_pages('sort_column=menu_order&title_li='); ?>
           </ul>
    	</div>
    
    	<div>
    <h2>Archives</h2>
    <?php wp_get_archives('type=monthly'); ?>
    <!-- end #sidebar2 --></div>

    Have no idea why this is not working for me.

    Thread Starter magicalwonders

    (@magicalwonders)

    O.K. I’ve played around with this and discovered that I can get the sidebar2.php showing on any page except the “News” page.

    In my Admin settings I have the static page set as – Front page: Home and Posts page: News

    So I suppose this is what is causing the problem. However, I need the archive to show on the “News” page, so not sure how to get around this problem.

    Any advice would be appreciated.

    Many thanks,

    Myles

    All right, that was important info.

    Since the News page is where your main loop is, then you have to use is_home, instead of is_page. That should make it work

    <?php if ( is_home() ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar1.php');?>
    <?php } ?>

    Let us know!

    Thread Starter magicalwonders

    (@magicalwonders)

    Hooray, it works! Thanks for the help, I really appreciate it.

    It’s a bit confusing though, setting it to “is_home” as it doesn’t actually go to the home page. Is that because the “Home page” has been set as static and therefore doesn’t contain a loop?

    Right. The static “Home page” is actually your “Front page” [is_front_page()], and ‘home’ is where the loop is, that is, your ‘News’ page [is_home()]. Let’s say it has been promoted from just a regular page, to the main page.

    Thread Starter magicalwonders

    (@magicalwonders)

    Hi buddha trance,

    Thanks for the explanation. Much appreciated.

    I’ve had a play around with the code and the following also works on the index page.

    <?php if ( is_home() ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php');?>
    <?php } else { ?>
    <?php get_sidebar(); ?>
    <?php } ?>

    I think I’m starting to get the hang of this php with WordPress stuff! lol.

    Hello, I’m pretty new to WordPress and I’m having some issues displaying 2 sidebars as well, I think my main problem is that I’m not sure where to set which page is the home page, My homepage right now will be the index but i wanted to see If someone would check out my code and point me in the right direction, so far I think I did the same as MagicalWonders and Buddha Trance but not quite sure where I’m going Wrong. Cheers and Many Thanks, here is my code.

    index.php

    <?php get_header(); ?>
        <div id="sub_container">
                <?php get_sidebar(); ?>
        	<div id="sub_main">
                <div id="sub_main_pic_top"></div>
            	<div id="sub_main_pic">
                	<img src="wp-content/themes/whiteboard/images/xsub_main_01.jpg" alt="Main Chapter Image" />
                </div>
                <div id="sub_main_pic_bott"></div>
            	<h3 id="titl_seven">Seven Extraordinary Things</h3>
                <div id="sub_main_curv_top"></div>
                <div id="sub_main_mid">
                	<h3>Welcome</h3>
                    <p>Seven Extraordinary Things is free online graphic novel written and illustrated by <a href="#">Doug Lefler</a>. New panels are added daily. If you miss any, go to <a href="#">Chapters</a>. If you want to get an idea where the story is headed, who is in it, or where it all takes place, check out <a href="#">Gallery</a>, <a href="#">Characters</a> and <a href="#">Locations</a>. If you’re curious what the Seven Extraordinary Things are, they can be found on <a href="#">The List</a>.</p>
              </div>
                <div id="sub_main_curv_bott"></div>
                <div id="sub_main_curv_top_out"></div>
                <div id="sub_main_mid_bg">
    <!-- POST INFORMATION -->
    <div class="post">
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
     <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
     <p>Written on <?php the_time('F j, Y'); ?> at <?php the_time() ?>, by <?php the_author() ?></p>
    
     <?php the_content(__('Read more'));?>
    
     <div class="postmeta">
      <p><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></p>
      <p>Category <?php the_category(', ') ?> | Tags: <?php the_tags(' ', ',', ' '); ?></p>
     </div><!-- end .postmeta -->
    
     <?php endwhile; else: ?>
      <p><strong>There has been a glitch in the Matrix.</strong><br />
      There is nothing to see here.</p>
      <p>Please try somewhere else.</p>
     <?php endif; ?>
    
     <div class="postnavigation">
      <p><?php next_posts_link('&laquo; Older Entries') ?><?php previous_posts_link(' | Newer Entries &raquo;') ?></p>
     </div> <!-- end .postnavigation -->
    
    </div> <!-- end .post -->
                </div>
                <div id="sub_main_curv_bott_out"></div>
            </div>
                <?php get_sidebar(); ?>
        </div>
    <?php get_footer(); ?>

    sidebar.php

    <?php if ( is_home() ) { ?>
    <?php include(TEMPLATEPATH.'/sidebar_left.php');?>
    <?php } else { ?>
    <?php get_sidebar(); ?>
    <?php } ?>

    sidebar_left.php

    <div id="sub_sidebar_left">
            	<h3 id="titl_chapters">Chapters</h3>
            		<ul>
                		<li><a id="chapter_01" title="Chapter 01" href="https://www.sevenextraordinarythings.com/">Chapter 01</a></li>
                		<li><a id="chapter_02" title="Chapter 02" href="https://www.sevenextraordinarythings.com/">Chapter 02</a></li>
                		<li><a id="chapter_03" title="Chapter 03" href="https://www.sevenextraordinarythings.com/">Chapter 03</a></li>
                		<li><a id="chapter_04" title="Chapter 04" href="https://www.sevenextraordinarythings.com/">Chapter 04</a></li>
                	</ul>
            	<div id="sub_sidebar_bott"></div>
            </div>

    sidebar_right.php

    <div id="sub_sidebar_right">
            	<h3 id="titl_characters">Characters</h3>
    		<ul>
                		<li><a id="character_01" title="Greg" href="https://www.sevenextraordinarythings.com/">Greg</a></li>
                		<li><a id="character_02" title="Claire" href="https://www.sevenextraordinarythings.com/">Claire</a></li>
                		<li><a id="character_03" title="Nina" href="https://www.sevenextraordinarythings.com/">Nina</a></li>
                		<li><a id="character_04" title="Harlan" href="https://www.sevenextraordinarythings.com/">Harlan</a></li>
                		<li><a id="character_05" title="Janis" href="https://www.sevenextraordinarythings.com/">Janis</a></li>
                		<li><a id="character_06" title="Minor" href="https://www.sevenextraordinarythings.com/">Minor</a></li>
                		<li><a id="character_07" title="Sheppard" href="https://www.sevenextraordinarythings.com/">Sheppard</a></li>
                		<li><a id="character_08" title="Ken" href="https://www.sevenextraordinarythings.com/">Ken</a></li>
                    </ul>
            	<div id="sub_sidebar_bott"></div>
            </div>

    Any help is greatly appreciated

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Code for calling Sidebars not working’ is closed to new replies.