• Resolved cajos1968

    (@cajos1968)


    Programming NOOB, looking for a way to add widget area to Vantage theme.

    I created a child theme,

    creaded CSS and Functions.php and copied Header.php

    Added to functions.php

    <?php // Opening PHP tag - nothing should be before this, not even whitespace
    
    // Custom Function to Include
    
    function vantage_widgets_init() {
    	register_sidebar( array(
    		'name' => __( 'Before Slider', 'vantage' ),
    		'id' => 'Before-Slider',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    Now according to documentation I should add “<?php dynamic_sidebar( ‘Before-Slider’);?>” to the header (copied to child)

    <?php
    /**
     * The Header for our theme.
     *
     * Displays all of the <head> section and everything up till <div id="main">
     *
     * @package vantage
     * @since vantage 1.0
     * @license GPL 2.0
     */
    ?><!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    	<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
    	<meta charset="<?php bloginfo( 'charset' ); ?>" />
    	<meta http-equiv="X-UA-Compatible" content="IE=10" />
    	<title><?php wp_title( '|', true, 'right' ); ?></title>
    	<link rel="profile" href="https://gmpg.org/xfn/11" />
    	<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    	<?php wp_head(); ?>
    </head>
    
    <body <?php body_class(); ?>>
    
    <?php do_action('vantage_before_page_wrapper') ?>
    
    <div id="page-wrapper">
    
    	<?php do_action( 'vantage_before_masthead' ); ?>
    
    	<?php get_template_part( 'parts/masthead', apply_filters( 'vantage_masthead_type', siteorigin_setting( 'layout_masthead' ) ) ); ?>
    
    	<?php do_action( 'vantage_after_masthead' ); ?>
    
    	<?php dynamic_sidebar( 'Before-Slider');?>
    
    	<?php vantage_render_slider() ?>
    
    	<?php do_action( 'vantage_before_main_container' ); ?>
    
    	<div id="main" class="site-main">
    		<div class="full-container">
    			<?php do_action( 'vantage_main_top' ); ?>

    As you probably guessed it ain’t working. Any help out there?

Viewing 15 replies - 1 through 15 (of 22 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’m a noob too but I think there are some differences in the parameters for the register_sidebar function that is defined in the Codex documentation:
    https://codex.www.ads-software.com/Function_Reference/register_sidebar#Parameters

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    id – Sidebar id – Must be all in lowercase, with no spaces (default is a numeric auto-incremented ID).

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Then your dynamic_sidebar call should also be lower case as so:

    <?php dynamic_sidebar( 'before-slider');?>

    Thread Starter cajos1968

    (@cajos1968)

    doesn’t change a thing.

    I changed

    <?php dynamic_sidebar( ‘before-slider’);?>

    to
    <?php register_sidebar( ‘before-slider’);?>

    or should it be vantage_widgets_init

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I changed

    <?php dynamic_sidebar( ‘before-slider’);?>

    to
    <?php register_sidebar( ‘before-slider’);?>

    Sorry not sure I understand, I thought you had this:

    register_sidebar( array(
    		'name' => __( 'Before Slider', 'vantage' ),
    		'id' => 'Before-Slider',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    Thread Starter cajos1968

    (@cajos1968)

    In the header file to call it. I try to figure out the peaces of the puzzle.

    functions.php of the child is loaded first and the parent is added.

    Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

    In my first post is my full funtcions.php of the child. Can anyone verify that this is correct?

    Hi Cajos,

    Try this: in your child theme, add a template file and call it sidebar-before-slider.php Inside this file enter the markup for your sidebar. Something like this:

    <?php if (! dynamic_sidebar ( 'sidebar-before-slider' ) ): ?>
    <h3 class="widget-title"><?php _e('Widgetized Sidebar', 'textdomain'); ?></h3>
    <p><?php _e('This panel is active and ready for you to add some widgets via the WP Admin', 'textdomain'); ?>
    </p>
    <?php endif; ?>

    Be careful: if you use upper case in your sidebar id, use uppercase here too, but lower case is better and more in accordance with convention. In place of text domain simply add your theme’s text domain for translation.

    Save this file, then go to your header.php file and call this sidebar in the exact location where you want it to appear:

    get_sidebar( 'before-slider' );

    I hope this helps ??
    -Maria Antonietta.

    Thread Starter cajos1968

    (@cajos1968)

    Should it be get_sidebar( ‘before-slider’ );

    or <?php get_sidebar( ‘before-slider’ ); ?>

    It depends: it’s a bit of php code, therefore, if you call the sidebar inside php tags there’s no need to add them (first option), but if you call the sidebar after some HTML, then wrap everything inside php tags (second option).

    Thread Starter cajos1968

    (@cajos1968)

    Yes got something (small steps)

    Widgetized Sidebar

    This panel is active and ready for you to add some widgets via the WP Admin

    Is now displayed in the area I want.

    Now how do i hook it up with a widget?

    That’s great! This is the expected behavior: it’s a message to the user that that area is ready to receive widgets. Now simply go to Appearance > Widgets, find your new sidebar and add widgets. Save your widgets and view the page. You should see the widgets displayed in the right place.

    Thread Starter cajos1968

    (@cajos1968)

    Ah there is what an issue. I don’t see the new widget there. Hmmmmm

    Did you place the widgets in your Before Slider sidebar? Did you save the widgets after adding them?

    Thread Starter cajos1968

    (@cajos1968)

    Like I said I’m a nood :p

    This is my functions.php in my child

    <?php
    function vantage_chid_widgets_init() {
    	register_sidebar( array(
    		'name' => 'Before Slider',
    		'id' => 'before-slider',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	));
    }
    
    add_action( 'widget_init', 'vantage_chid_widgets_init');

    As I understand it I should have a new widget called Before Slider.

    But I have not.

    Thread Starter cajos1968

    (@cajos1968)

    I used this video to create it

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Adding widget area in Vantage them’ is closed to new replies.