Crave: A modern WordPress theme with appetizing aesthetic


Results 1 to 8 of 8

Thread: WordPress conditional tags breaking my theme

  1. #1
    Join Date
    Sep 2012
    Location
    Ilkeston, Derbyshire, England
    Posts
    1,771

    Default WordPress conditional tags breaking my theme

    I hope someone can throw me a bone here because I've bulldozed through a lot of tutorials today trying to understand what I am doing wrong.

    In summary, I have been widgetizing the Magazine Pro theme from StudioPress, by registering new widgets and adding functions to functions.php.

    I have been able to do this successfully and call the widgets only on certain pages using conditional tags. The thing is, when I register and add another widget using similar conditional tags, it breaks the theme.

    It's strange because it is ONLY when I add the conditional tags to this second widget that the entire theme breaks.

    Here's an example:


    PHP Code:
    /** Register Widget Area */ 

    genesis_register_sidebar( array( 

        
    'id' => 'banners_2'
        
    'name' => __'Special Offers Page Below Header''mp' ), 
        
    'description' => __'Special Offers Posts Below Title.''mp' ), 

    ) ); 

    genesis_register_sidebar( array(
        
    'id'                => 'banners_3',
        
    'name'            => __'Special Offers Posts''mp' ),
        
    'description'    => __'More banners.''mp' ),
    ) );



    /** Add Widget Area */ 

    add_action'genesis_before_content''banners_2' ); 
    function 
    banners_2() { 

        if ( 
    is_page'specialoffers' ) || is_home() ) 
         


        echo 
    '<div class="banners-top widget-area">'
        
    dynamic_sidebar'banners_2' ); 
        echo 
    '</div>'




    add_action'genesis_entry_content''banners_3' ); 
    function 
    banners_3() { 



        echo 
    '<div class="banners-top widget-area">'
        
    dynamic_sidebar'banners_3' ); 
        echo 
    '</div>'


    You can see the first instance of a conditional tag where I am calling the widget to sit on a particular Genesis Hook on two particular pages:

    PHP Code:
        if ( is_page'specialoffers' ) || is_home() ) 
         

    If I try and add another tag to the second widget ID (banners3) I get a blank white page with an error.

    This is what I've been trying to add to the second widget:

    PHP Code:
    add_action'genesis_entry_content''banners_3' ); 
    function 
    banners_3() { 

        if ( 
    is_single()  ) 
         


        echo 
    '<div class="banners-top widget-area">'
        
    dynamic_sidebar'banners_3' ); 
        echo 
    '</div>'


    Both widgets are referencing the same div class because I have set up a certain style. It's been driving me absolutely mental, and I know I won't be able to let go of this. This is probably going to drag on for weeks and weeks. I could compromise the design of the site by just avoid this functionality but I am determined to learn.

    A lot of tutorials I've been reading are often vague, or outdated or just missing vital info.

    If anyone can help me on this I'll be very grateful and do my best to reciprocate however I can

  2. #2
    Join Date
    Apr 2007
    Posts
    15,133

    Default

    Whoa, you are way further deep than I am on this. Have you thought of asking Studiopress for support? I wonder if their support covers coding. I've never emailed them for any custom coding questions.

  3. #3
    Join Date
    Sep 2012
    Location
    Ilkeston, Derbyshire, England
    Posts
    1,771

    Default

    Well I might have to do that eventually, but before I do I wait and see if anybody here on the forum is prepared to throw in their two cents.

    By the way, the tutorial I used to help build the widgets is here:

    http://journalxtra.com/easyguides/ho...-child-themes/


    The Genesis Hook I am trying to hang the second widget on is genesis_entry_content

    You can find all the hooks here

    And here are the WordPress conditional tags

    Hopefully someone can chime in and help us both.

    Thanks in advance to whoever is willing to share their knowledge

  4. #4
    Join Date
    Apr 2007
    Posts
    15,133

    Default

    Appreciate you posting those additional tutorials.

  5. #5
    Join Date
    May 2013
    Posts
    3

    Default

    There's 5 problems with your code.

    1. You're using a function name which is exactly the same as your widget i.d which will cause problems.
    2. It looks like you have 2 opening curly brackets but only 1 closing curly bracket so add another.
    3. Should always use genesis_widget_area rather than dynamic_sidebar
    4. Should use the page slug or i.d rather than the name
    5. The widget is coded for themes running XHTML markup and NOT HTML 5

    PHP Code:
    /** Register Widget Area */  

    genesis_register_sidebar( array(  

        
    'id' => 'banners-2',  
        
    'name' => __'Special Offers Page Below Header''mp' ),  
        
    'description' => __'Special Offers Posts Below Title.''mp' ),  

    ) );  

    genesis_register_sidebar( array( 
        
    'id'                => 'banners-3'
        
    'name'            => __'Special Offers Posts''mp' ), 
        
    'description'    => __'More banners.''mp' ), 
    ) ); 



    /** Add Widget Area */  

    add_action'genesis_before_content''add_banner_widget_two' );  
    function 
    add_banner_widget_two() {  

    if ( 
    is_page'specialoffers' ) || is_home() && is_active_sidebar'banners-2' )) { 

        
    genesis_widget_area'banners-2', array(
                
    'before' => '<div class="banners-top widget-area">',
                
    'after'     => '</div>',
            ) ); 
        }
    }  


    add_action'genesis_entry_content''banner_widget_three' );  
    function 
    banner_widget_three() { 

    if ( 
    is_single() && is_active_sidebar'banners-3' )) {
        
        
    genesis_widget_area'banners-3', array(
                
    'before' => '<div class="banners-top widget-area">',
                
    'after'     => '</div>',
            ) ); 
        }

    Last edited by braddalton; 03-04-2014 at 12:06 AM.

  6. #6
    Join Date
    Apr 2007
    Posts
    15,133

    Default

    Quote Originally Posted by braddalton View Post
    There's 5 problems with your code.

    1. You're using a function name which is exactly the same as your widget i.d which will cause problems.
    2. It looks like you have 2 opening curly brackets but only 1 closing curly bracket so add another.
    3. Should always use genesis_widget_area rather than dynamic_sidebar
    4. Should use the page slug or i.d rather than the name
    5. The widget is coded for themes running XHTML markup and NOT HTML 5

    PHP Code:
    /** Register Widget Area */  

    genesis_register_sidebar( array(  

        
    'id' => 'banners-2',  
        
    'name' => __'Special Offers Page Below Header''mp' ),  
        
    'description' => __'Special Offers Posts Below Title.''mp' ),  

    ) );  

    genesis_register_sidebar( array( 
        
    'id'                => 'banners-3'
        
    'name'            => __'Special Offers Posts''mp' ), 
        
    'description'    => __'More banners.''mp' ), 
    ) ); 



    /** Add Widget Area */  

    add_action'genesis_before_content''add_banner_widget_two' );  
    function 
    add_banner_widget_two() {  

    if ( 
    is_page'specialoffers' ) || is_home() )  {  

        
    genesis_widget_area'banners-2', array(
                
    'before' => '<div class="banners-top widget-area">',
                
    'after'     => '</div>',
            ) ); 
        }
    }  


    add_action'genesis_entry_content''banner_widget_three' );  
    function 
    banner_widget_three() { 

    if ( 
    is_single() ) {
        
        
    genesis_widget_area'banners-3', array(
                
    'before' => '<div class="banners-top widget-area">',
                
    'after'     => '</div>',
            ) ); 
        }

    Hey, it's Brad from WPSites! Cool. Did you lose your old login credentials? If so I can reset them.

  7. #7
    Join Date
    Sep 2012
    Location
    Ilkeston, Derbyshire, England
    Posts
    1,771

    Default

    Thanks Brad! I appreciate that you also replied to my initial post on the StudioPress forums and even signed up here to reply to this thread. Thanks so much. I think my main issue is the missing closing curly bracket. I am taking on board your other comments too, and thanks for rewriting my code

    P.S. Thanks again, everything is working smoothly and I'll now be able to reference this working code for the future. Much obliged to you Brad
    Last edited by Darren; 03-03-2014 at 08:47 PM. Reason: Thanks again!

  8. #8
    Join Date
    May 2013
    Posts
    3

    Default

    Must have Lisa.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •