• Resolved G.S.

    (@gs-1)


    Hi Tom,

    I have created a custom page template with name custom_page.php and I have uploaded this file in child theme that I have downloaded from here : http://generatepress.com/knowledgebase/child-theme-working/

    In custom_page.php I have pasted the code that there is in page.php in this way I have created my custom page template.
    I called in the file custom_page.php the new widgets in this way :

    <div class="grid-container">
    		<div class="grid-33"><?php dynamic_sidebar( 'left-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'mid-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'right-top' ); ?></div>
    	</div>

    After in the file function.php I have used the following code :

    <?php
    /**
     * Generate child theme functions and definitions
     *
     * @package Generate
     */
    
    add_action( 'widgets_init', 'generate_custom_widgets_init' );
    function generate_custom_widgets_init() {
    	register_sidebar( array(
    		'name'          => __( 'Left Top', 'generate' ),
    		'id'            => 'left-top',
    		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
    		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
    	) );
    
    	register_sidebar( array(
    		'name'          => __( 'Mid Top', 'generate' ),
    		'id'            => 'mid-top',
    		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
    		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
    	) );
    
    	register_sidebar( array(
    		'name'          => __( 'Right Top', 'generate' ),
    		'id'            => 'right-top',
    		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
    		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
    	) );
    
    }

    In this way If I go in Appearance/Widgets I see the sidebar that I have created :
    – Left top
    – Mid Top
    – Right Top

    However If I go in Page/All Page/ and I select the template “Custom Page” for my Home, I’m getting syntax error on my custom_page.php (line 36).

    Do you know what can I do for fix that?

    Thanks

    Giuseppe

Viewing 12 replies - 1 through 12 (of 12 total)
  • However If I go in Page/All Page/ and I select the template “Custom Page” for my Home, I’m getting syntax error on my custom_page.php (line 36).

    what is the exact full text of the syntax error?
    what is the full code of custom_page.php?

    Thread Starter G.S.

    (@gs-1)

    Hi alchymyth

    thanks for your answer.

    In this moment my site running in localhost.

    The exact full text of the syntax error is :

    Parse error: syntax error, unexpected ‘<‘ in C:\Users\GIUSEPPE\Documents\xampp offline\htdocs\caldaieimpianti\wp-content\themes\generatepress_child\custom_page.php on line 36

    The full code of custom_page.php is :

    <?php
    /*
    Template Name: Custom Page
    */
    
    get_header(); ?>
    
    	<div id="primary" <?php generate_content_class();?>>
    		<main id="main" <?php generate_main_class(); ?> itemprop="mainContentOfPage" role="main">
    			<?php do_action('generate_before_main_content'); ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'content', 'page' ); ?>
    
    				<?php
    				// If comments are open or we have at least one comment, load up the comment template
    				if ( comments_open() || '0' != get_comments_number() ) : ?>
    					<div class="comments-area">
    						<?php comments_template(); ?>
    					</div>
    				<?php endif; ?>
    
    			<?php endwhile; // end of the loop. ?>
    			<?php do_action('generate_after_main_content'); ?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php
    do_action('generate_sidebars');
    get_footer();
    
    <div class="grid-container">
    		<div class="grid-33"><?php dynamic_sidebar( 'left-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'mid-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'right-top' ); ?></div>
    	</div>

    add the closing php tag after this line:

    get_footer();

    i.e. make it like:

    get_footer(); ?>

    also, be aware that adding any html after the ‘get_footer()’ code will lead to invalid html of your site, and might lead to browser incompatibility.

    Theme Author Tom

    (@edge22)

    As stated above (thanks!), this is the issue:

    get_footer();
    
    <div class="grid-container">
    		<div class="grid-33"><?php dynamic_sidebar( 'left-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'mid-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'right-top' ); ?></div>
    	</div>

    It should be:

    get_footer(); ?>
    
    <div class="grid-container">
    		<div class="grid-33"><?php dynamic_sidebar( 'left-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'mid-top' ); ?></div>
    		<div class="grid-33"><?php dynamic_sidebar( 'right-top' ); ?></div>
    	</div>

    That being said, why are you adding these areas below the footer? Is that where you’re wanting them to show up?

    Thread Starter G.S.

    (@gs-1)

    Hi Tom and alchymyth ,

    thanks for your answers.

    also, be aware that adding any html after the ‘get_footer()’ code will lead to invalid html of your site, and might lead to browser incompatibility.

    Where should I put those items to get a valid html code?

    That being said, why are you adding these areas below the footer? Is that where you’re wanting them to show up?

    No Tom, I do not want those areas in the footer.
    But I want those areas to the side of the page.
    So where should I put the following items? :

    <div class = “grid-container”>
    <div class = “grid-33”> <? php dynamic_sidebar (‘left-top’); ?> </ div>
    <div class = “grid-33”> <? php dynamic_sidebar (‘mid-top’); ?> </ div>
    <div class = “grid-33”> <? php dynamic_sidebar (‘top-right’); ?> </ div>
    </ div>

    Thanks for your precious support!!!

    Giuseppe

    Thread Starter G.S.

    (@gs-1)

    That being said, why are you adding these areas below the footer? Is that where you’re wanting them to show up?

    Tom,

    To be exact, I would like those areas on the right side of the page.

    Thanks

    Giuseppe

    Theme Author Tom

    (@edge22)

    Why not use the built in Right Sidebar widget area? Any specific reason?

    Thread Starter G.S.

    (@gs-1)

    Hi Tom,

    now I try to explain what I want.
    I have created a custom page template because in this page I want some widgets with different content than the widgets of other pages .
    For accuracy, I want that the widgets with different content, appear in the right side of the custom page template.

    Why not use the built in Right Sidebar widget area? Any specific reason?

    Because If I go in Appearance/Widget and put widgets with different content in right sidebar,when I go in my custom page template I see them, but I see also the widgets of others pages.

    Can you tell me how I can get the desired result?

    Thanks

    Giuseppe

    Thread Starter G.S.

    (@gs-1)

    Hi Tom,

    only one thing, my question is not clear, or it is impossible to do what I asked?

    Thanks

    Giuseppe

    Theme Author Tom

    (@edge22)

    How about using a plugin like this?: https://wordpress.org/plugins/display-widgets/

    It allows you to set different widgets for different pages 🙂

    Thread Starter G.S.

    (@gs-1)

    Thanks,

    I’ll use this plugin!

    ;=)

    Theme Author Tom

    (@edge22)

    Awesome 🙂

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Adding new widgets in new page template’ is closed to new replies.