1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Conditional Sidebar elements. How in Wordpress?

Discussion in 'Content Management' started by Axus Technologies Inc., Aug 16, 2010.

  1. #1
    Hi..
    Im doing a client's website, who has 10 different posts on the main nav bar and on those 10 different posts pages, he needs different elements on each of their sidebars on those posts pages.


    So, how do we do that ?

    P.S : Im asking posts, not pages. This is not a blog and a company website. And he is not using WP pages for his site pages, but WP posts. :cool:
     
    Axus Technologies Inc., Aug 16, 2010 IP
  2. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #2
    use Conditional Tags and create widget for each post
    is_single()
    http://codex.wordpress.org/Conditional_Tags
    Code (markup):
     
    bhuthecoder, Aug 16, 2010 IP
  3. Axus Technologies Inc.

    Axus Technologies Inc. Peon

    Messages:
    599
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi..
    Thanks for your reply.

    Can you just do a sample example ,

    Like, if the Post-ID is 15 and the post slug is, about-us.

    And we want on sidebar,
    <b>xyz</b>
     
    Axus Technologies Inc., Aug 16, 2010 IP
  4. extremephp

    extremephp Peon

    Messages:
    1,290
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, this is the way to Accomplish this the easiest way!!

    
        <?php
            $homepage = "URL TO THE POST TO SHOW <b> XYZ</b>/";
            $currentpage = $_SERVER['REQUEST_URI'];
            if($homepage==$currentpage) {
            echo "<b>xyz</b>";
            }
        ?>
        
    Code (markup):
    You should put this in the Sidebar.php to get it on the sidebar!! you can use the Divs, or insert between the existing Divs to stylize it!!

    So If you have 10 posts, You should Copy these 10 times with the Required url and the content needed. Out of those 10, in which homepage=currentpage gets validated, will be echoed, rest will be avoided!!

    Got it?

    Whoosh!! That was hard Typing!!

    ~ExP~
     
    Last edited: Aug 16, 2010
    extremephp, Aug 16, 2010 IP
  5. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #5
    
    if (is_single(15)) {
    		<div id="custom-widget" class="widget-area" role="complementary">
    			<ul class="xoxo">
    				<?php dynamic_sidebar( 'custom-widget-area' ); ?>
    			</ul>
    		</div>
    }
    else {
       <?php get_sidebar(); ?> //default sidebar
    }
    
    
    Code (markup):
     
    bhuthecoder, Aug 16, 2010 IP
  6. extremephp

    extremephp Peon

    Messages:
    1,290
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You Managed It from the Wordpress Aspect !! But I considered it as a Php supported Website :p

    Good Work In The End!!

    ~ExP~

    ADDITION:


    You can use this to do all at a Go!!

    
    <?php if (is_page('1')) { include("sidebar3.php"); }
    
    elseif (is_page('green-page')) { include("sidebar2.php"); }
    
    elseif (is_page('another-page')) { include("sidebar3.php"); }
    
    else { include("sidebar.php"); 
    
    } ?>
    
    Code (markup):
     
    Last edited: Aug 16, 2010
    extremephp, Aug 16, 2010 IP
  7. Axus Technologies Inc.

    Axus Technologies Inc. Peon

    Messages:
    599
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    custom-widget-area

    Where does that widget exist ?

    I dont think, WP allows you to make multiple widget groups.
     
    Axus Technologies Inc., Aug 16, 2010 IP
  8. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #8
    
    	register_sidebar( array(
    		'name' => __( 'custom Widget Area', 'bhuthecoder' ),
    		'id' => 'custom-widget-area',
    		'description' => __( 'The custom widget area', 'bhuthecoder' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    Code (markup):
    put this code in function.php (located in themes folder)
    it will create a widget with name "custom Widget Area"

    and u can call this widget using below code
    <?php dynamic_sidebar( 'custom-widget-area' ); ?>
    
    Code (markup):
     
    bhuthecoder, Aug 16, 2010 IP
  9. Axus Technologies Inc.

    Axus Technologies Inc. Peon

    Messages:
    599
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ok got it.

    Thanks man.
    +rep added..
     
    Axus Technologies Inc., Aug 16, 2010 IP