• Resolved fibroidcincinnati

    (@fibroidcincinnati)


    I added a widget area below the hero area prior to the first original widget area. To do this, I added the following to a cloned functions.php file in my child theme to initialize three new widget areas:

    function arphabet_widgets_init() {

    register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 1',
    		'id'            => 'front_sub_hero1',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="rounded">',
    		'after_title'   => '</h2>',
    	) );
    
    	register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 2',
    		'id'            => 'front_sub_hero2',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="rounded">',
    		'after_title'   => '</h2>',
    	) );
    
    	register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 3',
    		'id'            => 'front_sub_hero3',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="rounded">',
    		'after_title'   => '</h2>',
    	) );
    
    }
    add_action( 'widgets_init', 'arphabet_widgets_init' );
    ?>

    I then cloned the front-page.php to my child theme and added code that activated these three areas between the original primary and secondary areas:

    <div id="primary-sidebar" class="widget-area front-widget-area" role="complementary">
    		<?php dynamic_sidebar( 'front_sub_hero1' ); ?>
    		<?php dynamic_sidebar( 'front_sub_hero2' ); ?>
    		<?php dynamic_sidebar( 'front_sub_hero3' ); ?>
    	</div><!-- #primary-sidebar -->

    I added a text widget to each of these new sub-hero areas to see what would happen and the widget areas are working and appearing. However, the problem is that they are in a running fashion vertically.

    I then added a second text widget to the first added widget area, and the widgets are running vertically within the individual widget areas also. I need to get the widgets to run horizontally across the page somehow. Either by getting one of the widget areas to display its widgets horizontally, or by getting the three new widgets areas themselves to align horizontally (just as the theme frontpage widget columns align horizontally).

    I looked at the CSS for the original widget columns to see how they get aligned horizontally and found this (which I think is related) in the parent theme style.css:

    /* Front Page & Footer Widget Areas */
    	.footer-widget-area .widget-area {
    		margin: 0;
    	}
    	.front-widget-area .widget-area,
    	.footer-widget-area .widget-area {
    		float: left;
    	}
    	.front-widget-area .widget-area:nth-child(1):nth-last-child(1),
    	.footer-widget-area .widget-area:nth-child(1):nth-last-child(1) {
    		width: 100%;
    	}
    	.front-widget-area .widget-area:nth-child(1):nth-last-child(2),
    	.front-widget-area .widget-area:nth-child(2):nth-last-child(1),
    	.footer-widget-area .widget-area:nth-child(1):nth-last-child(2),
    	.footer-widget-area .widget-area:nth-child(2):nth-last-child(1) {
    		margin-right: 6%;
    		width: 47%;
    	}
    	.front-widget-area .widget-area:nth-child(1):nth-last-child(2):last-of-type,
    	.front-widget-area .widget-area:nth-child(2):nth-last-child(1):last-of-type,
    	.footer-widget-area .widget-area:nth-child(1):nth-last-child(2):last-of-type,
    	.footer-widget-area .widget-area:nth-child(2):nth-last-child(1):last-of-type {
    		margin-right: 0;
    	}
    	.front-widget-area .widget-area:nth-child(1):nth-last-child(3),
    	.front-widget-area .widget-area:nth-child(2):nth-last-child(2),
    	.front-widget-area .widget-area:nth-child(3):nth-last-child(1),
    	.footer-widget-area .widget-area:nth-child(1):nth-last-child(3),
    	.footer-widget-area .widget-area:nth-child(2):nth-last-child(2),
    	.footer-widget-area .widget-area:nth-child(3):nth-last-child(1) {
    		margin-right: 5%;
    		width: 30%;
    	}
    	.front-widget-area .widget-area:nth-child(1):nth-last-child(3):last-of-type,
    	.front-widget-area .widget-area:nth-child(2):nth-last-child(2):last-of-type,
    	.front-widget-area .widget-area:nth-child(3):nth-last-child(1):last-of-type,
    	.footer-widget-area .widget-area:nth-child(1):nth-last-child(3):last-of-type,
    	.footer-widget-area .widget-area:nth-child(2):nth-last-child(2):last-of-type,
    	.footer-widget-area .widget-area:nth-child(3):nth-last-child(1):last-of-type {
    		margin-right: 0;
    	}
    }

    Can I somehow apply this to the widget areas I have added to get them to display horizontally?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fibroidcincinnati

    (@fibroidcincinnati)

    So I made a little progress by adding a class to the div section i added to the frontpage template. I added one called “subhero”. I then went to my Edit CSS and added this to the stylesheet:

    .subhero {
    	display: flex;
    }

    which now makes them all flex across the page horizontally… HOWEVER, they do not wrap as the screen size changes with smaller screens or portable devices… so is there a way to apply the wrapping that is defined above to this as screen size changes?

    Thread Starter fibroidcincinnati

    (@fibroidcincinnati)

    i totally just got this to work. I am posting the solution here in case anyone else ever needs it. i have seen many people ask for ways to add text or other things below the hero image and this can accomplish that too so many might find it useful.

    This is to modify the frontpage template to 1. Add a widget area beneath the hero section and above the frontpage widget areas for three columns of widgets. These column areas appear under Appearance -> Widgets just as the frontpage widget columns appear. It essentially duplicates the look and functionality of the frontpage widget area.

    1. create a child with the appropriate functions.php file.
    2. Modify the functions.php file to add the following code. This will create the three widget areas and activate them for the appearance section:

    /**
     * Register the subhero widgetized areas.
     *
     */
    function arphabet_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 1',
    		'id'            => 'front-sub-hero1',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    
    	register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 2',
    		'id'            => 'front-sub-hero2',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    
    	register_sidebar( array(
    		'name'          => 'Frontpage sub-hero area 3',
    		'id'            => 'front-sub-hero3',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    
    }
    add_action( 'widgets_init', 'arphabet_widgets_init' );
    ?>

    3. copy the front-page.php file to your child with the appropriate permissions so you can modify it
    4. Modify the front-page.php file by adding the following. You want to add it after </div><!– #primary –> and before <?php get_sidebar( ‘front-page’ ); ?>. This will pull the three widget areas into the frontpage defined by a subhero class that we will style. At first they will run vertically and not in columns but we’ll fix that in the next step:

    <div id="primary-subhero-sidebar" class="front-widget-area widget-area" role="complementary">
    
    		<div id="primary-subhero-sidebar-1" class="subhero-1">
    			<?php if ( is_active_sidebar( 'front-sub-hero1' ) ) : ?>
    				<?php dynamic_sidebar( 'front-sub-hero1' ); ?>
    			<?php endif; ?>
    		</div><!-- #primary-subhero-sidebar-1 -->
    
    		<div id="primary-subhero-sidebar-2" class="subhero-2">
    			<?php if ( is_active_sidebar( 'front-sub-hero2' ) ) : ?>
    				<?php dynamic_sidebar( 'front-sub-hero2' ); ?>
    			<?php endif; ?>
    		</div><!-- #primary-subhero-sidebar-2 -->
    
    		<div id="primary-subhero-sidebar-3" class="subhero-3">
    			<?php if ( is_active_sidebar( 'front-sub-hero3' ) ) : ?>
    				<?php dynamic_sidebar( 'front-sub-hero3' ); ?>
    			<?php endif; ?>
    		</div><!-- #primary-subhero-sidebar-3 -->
    	</div><!-- #primary-subhero-sidebar -->

    5. Style the three widget areas into columns to match the frontpage area below them. Do this by going to Edit CSS to add code to the stylesheet (style.css). Add this code:

    /* Front Page subhero Widget Area */
    @media screen and (min-width: 768px) {
    	.subhero-1 {
    		float: left;
    		width: 30%;
    		margin-right: 5%;
    	}
    
    	.subhero-2 {
    		float: left;
    		width: 30%;
    		margin-right: 5%;
    	}
    
    	.subhero-3 {
    		float: right;
    		width: 30%;
    		margin-right: 0;
    	}
    }

    That should style them just like the area below. And it also will allow them to run into one column as the screen size decreases at the same value the rest of the page does. So three columns when the area below is three columns, and one column when the area below is one column.

    Note that I didn’t go the added step to make sure the columns resized if you didn’t use all three of the new widget columns. This layout is specifically for the use of all three at the same time.

    You could easily modify what I have done with the CSS to change the number of areas and adjust the styling /layout accordingly just by changing the values etc. For example, for one column, just reduce the number of widgets you register (in the code above) in the functions.php to only one subhero widget area. Reduce the number of areas you pull in the frontpage.php to this one area. Then, change the style values to width 100% or whatever you want etc.

    This way you could not only add a text area below the hero, but add any widget(s) below the hero.

    Very proud of myself!

    Thread Starter fibroidcincinnati

    (@fibroidcincinnati)

    Just marking my own thread as resolved…

    Moderator Kathryn Presner

    (@zoonini)

    Glad you found a solution – and thanks a bunch for sharing it with other Sela users!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sela added widget area alignment issue’ is closed to new replies.