WordPress.org

Ready to get started?Download WordPress

Forums

Genesis Featured Widget Amplified
[resolved] Conditional Tags (4 posts)

  1. nickhempsey
    Member
    Posted 3 years ago #

    I'm trying to use conditional tags in the sidebar, but not having any luck getting it to work properly.

    I'm using the gfwa_after_post_content hook to add in a few social sharing buttons to the posts on the homepage.

    When I drop in the widget to the sidebar that hook is generating in the sidebars as well, which I don't want. So I created a conditional tag to what I thought would remove it from the sidebar.

    Here is my code:

    <?php if ( !is_active_sidebar() ) {?>
    <div id="featured-social">
    
    	<div id="featured-twitter">
    		<?php do_action('stc_tweetbutton'); ?>
    	</div><!-- end #featured-twitter -->
    
    	<div id="featured-facebook">
    		<?php do_action('sfc_share_button'); ?>
    	</div><!-- end #featured-facebook -->
    
    	<div id="featured-linkedin">
    		<?php do_action('linkedin_button'); ?>
    	</div><!-- end #featured-linkedin -->
    
    </div><!-- end #featured-social -->
    <?php } ?>

    This is in a file called featured_social.php which I'm calling in funtions.php via:

    // Add Social Buttons to Featured Widget
    add_action('gfwa_after_post_content', 'include_featured_social');
    function include_featured_social() {
        require(CHILD_DIR.'/featured-social.php');
    }

    I just get an error when I bring it live. I tried it without the conditional tag and it works fine. Any ideas what I did wrong?

    http://wordpress.org/extend/plugins/genesis-featured-widget-amplified/

  2. Nick the Geek
    Member
    Plugin Author

    Posted 3 years ago #

    The code you will need to test again is part of the $instance value. You can either add a new value to the options, or use an existing value. To make this easier I think I'll add a field for setting a value to test against in another version.

    For now, is there anything different about the settings between the widgets right now?

  3. nickhempsey
    Member
    Posted 3 years ago #

    There are few differences in the widgets.

    Post Image Size:
    Home - 150x150 Aligned Left Before
    Sidebar - 80x80 Aligned Left Before

    Post Content Limiting:
    Home - 500 characters
    Sidebar - 100 characters

    Post Info:
    Home - Enabled
    Sidebar - Disabled

    Pagination:
    Home - Enabled
    Sidebar - Disabled

    I kind of understand what you're saying... I'm just learning php so you have to talk to me like a baby. haha.

  4. Nick the Geek
    Member
    Plugin Author

    Posted 3 years ago #

    NP, ok, so the pagination or post info would be the easiest to test against at this time.

    // Add Social Buttons to Featured Widget
    add_action('gfwa_after_post_content', 'include_featured_social');
    function include_featured_social($instance) {
    if ( !empty( $instance['show_byline'] ) )
        require(CHILD_DIR.'/featured-social.php');
    }

    This will cause the file to only load on that hook when the post info is selected, which it isn't for your sidebar. You can drop the conditional in the featured-social.php file.

    Also, like I said I'm going to add a field just for this type of thing. I have filters in place to make it possible to add options to the widget form, but having a text field to test against will make it even easier.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic