Output the content of the primary sidebar widget in the main content

Community Forums Forums General Discussion Output the content of the primary sidebar widget in the main content

This topic is: not resolved

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  Tijmen 12 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #69475

    Tijmen
    Member
    Post count: 9

    A client of mine has some content in the primary widget that he would like to show on the homepage. But the homepage, unlike the other pages doesn’t have a sidebar. So I need to load the content of the widget in another location.

    I figured out how to do that with the code below. It loads the content of the two widgets and outputs it.

    	genesis_widget_area( 'popular-stuff', array(
    		'before' => '<div id="popular-stuff"><div class="wrap">',
    		'after' => '</div></div>',
    	) );	
    	
    	genesis_markup( array(
    		'html5'   => '<aside %s>',
    		'xhtml'   => '<div id="about-fp">',
    		'context' => 'sidebar-primary',
    	) );
    		
    	do_action( 'genesis_before_sidebar_widget_area' );
    	do_action( 'genesis_sidebar' );
    	do_action( 'genesis_after_sidebar_widget_area' );
    	
    	genesis_markup( array(
    		'html5' => '</aside>', //* end .sidebar-primary
    		'xhtml' => '</div>', //* end #sidebar
    	) );
    
    	remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );

    But that problem is that after those two widgets it also outputs the code below.

    
    <div id="content-sidebar-wrap"><div class="hfeed" id="content"></div><div class="sidebar widget-area" id="sidebar"></div></div>

    If I remove the do_action parts from the code above, there is no output at all. If I remove the remove_action, the empty sidebar div contains the content of the sidebar-primary. But then the primary content is displayed twice. Once in the html above, and one time after the popular widget content. So that’s also not what I want.

    Is there a better way to fix this, so that the output only happens once and doesn’t include the empty html tags? I’m aware I can just add display:none to the content-sidebar-wrap div and hide it, but if there is a cleaner fix I would prefer to use that :)

    • This topic was modified 12 months ago by  Tijmen.
    • This topic was modified 12 months ago by  Tijmen.
    • This topic was modified 12 months ago by  Tijmen.
    • This topic was modified 12 months ago by  Tijmen.
    • This topic was modified 12 months ago by  Tijmen.
    • This topic was modified 12 months ago by  Tijmen.
    #69849

    nutsandbolts
    Moderator
    Post count: 3172

    Can you provide a link to the site? I’m trying to picture this in my head but it would be much easier if we could see what’s happening with the layout.


    Andrea Whitmer, Owner, Nuts and Bolts Media
    I provide dev and training services for web designers • Find me on Twitter and Google+

    #69864

    Tijmen
    Member
    Post count: 9

    I fixed it already, the function that contained the code was linked to an action that called genesis_before_sidebar, I changed that to genesis_before_content and that made the html output look normal again :)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.