Adding new widgets in new page template
-
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 : https://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 TopHowever 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
- The topic ‘Adding new widgets in new page template’ is closed to new replies.