Need help with PHP in wordpress

Discussion in 'PHP' started by geekology, Apr 5, 2009.

  1. #1
    I want to show my blog's sidebars depending on the page URL.
    So if the page URL is http://xyz.com/abc then the sidebars should not be shown otherwise they should.

    I tried making some changes in my page.php file under wordpress but its not working.

    Here is the code I used:

    <?php If (get_permalink() != "http://xyz.com/abc") then ?>
    
    <?php get_sidebar(); ?> 
    PHP:
    Can someone tell me what am I doing wrong?
     
    geekology, Apr 5, 2009 IP
  2. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #2
    replace 45 with your page ID.

    
    <?php 
    if (is_page('45'))
     {
    	echo ' ' ;
    } 
    
    else {
    	echo get_sidebar();
    }
    
     ?>
    
    
    Code (markup):
     
    MeetHere, Apr 5, 2009 IP
  3. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thanks MeetHere.

    There is still an issue. Though the right sidebar has gone but the left sidebar is still visible. What can I do to remove that?

    FYI... I am using copyblogger's three column theme.
     
    geekology, Apr 5, 2009 IP
  4. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #4
    use echo sidebar1, sidebar2 - whatever type of file it is..
     
    MeetHere, Apr 5, 2009 IP
  5. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #5
    I didn't get that MeetHere :(

    I want to remove the sidebars not show them. I guess echo will make them visible.
     
    geekology, Apr 6, 2009 IP
  6. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #6
    no man, we are doing "else" command..
    we used echo' ' (here we kept nothing in between ' ' )

    <?php 
    if (is_page('45'))
     {
    	echo ' ' ;
    } 
    
    else {
    	echo get_sidebar2();
    }
    
     ?>
    
    <?php 
    if (is_page('45'))
     {
    	echo ' ' ;
    } 
    
    else {
    	echo get_sidebar1();
    }
    
     ?>
    Code (markup):
     
    MeetHere, Apr 6, 2009 IP
  7. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #7
    oh ok If you mean that ... I know.

    But the issue is in my page.php file I don't find any reference to my left sidebar... there is a reference to get_sidebar(). Now sidebar.php again has no reference to left sidebar

    probably if it is possible for you to check copyblogger 3 column theme, you will understand it more clearly.
     
    geekology, Apr 6, 2009 IP
  8. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #8
    find it man.. you will get it...
     
    MeetHere, Apr 6, 2009 IP
  9. pipes

    pipes Prominent Member

    Messages:
    12,766
    Likes Received:
    958
    Best Answers:
    0
    Trophy Points:
    360
    #9
    Did you get this problem sorted?
     
    pipes, Apr 12, 2009 IP
  10. geekology

    geekology Well-Known Member

    Messages:
    545
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #10
    Yes pipes ... It got sorted..

    Though right sidebar was pretty straightforward but for left sidebar I had to go inside leftsidebar.php file and put my if-else conditions there.

    Thanks for asking, appreciate it.
     
    geekology, Apr 12, 2009 IP
  11. pipes

    pipes Prominent Member

    Messages:
    12,766
    Likes Received:
    958
    Best Answers:
    0
    Trophy Points:
    360
    #11
    Good, im pleased you got it sorted. :)
     
    pipes, Apr 13, 2009 IP