Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add a Widget to Page Template
Tagged: adding widgets, Page Templates, widgets
- This topic has 4 replies, 3 voices, and was last updated 8 years, 8 months ago by LeaChristine.
-
AuthorPosts
-
July 27, 2015 at 1:44 pm #160612LeaChristineMember
Hi there, I have a question about displaying a widget area only on pages that have a given page template assigned to them. Can someone please help me with this, and let me know if it's even possible?
I have a slider that I want to display *only* on my site's About Page-- however, I'm also using Advanced Custom Fields for the About page's content area, so I need to create a page template for it. But when I assign the About template to the About page, my slider disappears. Here is the code I have so far trying to get this to work:
functions.php code:
//* Register widget for SLIDER genesis_register_sidebar( array( 'id' => 'slider', 'name' => __( 'Slider Area' ), 'description' => __( 'This is the area where the slider is displayed' ), ) );
about.php code:
<?php /** * Template Name: About Page * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ get_header(); ?> <?php //* Hook social widget area in header add_action( 'genesis_before_content', 'slider'); function slider() { // If it's the About page, display slider if (is_page( 'about' ) ) { genesis_widget_area( 'slider', array( 'before' => '<div class="slider">', 'after' => '</div>', ) ); } } ?> <div class="content"> <div class="entry"> <?php if ( have_rows('story_title') ): while ( have_rows('story_title') ): the_row(); ?> <h3><?php the_field('story_title'); ?></h3> <?php endwhile; endif; ?> </div><!-- #entry --> </div><!-- #content --> <?php get_footer(); ?>
I have already tried registering the widget in only the functions.php, and only in the about.php. Neither approaches are working. Any help you can give me would be much appreciated. Thanks!
http://sample.leachristinedesigns.com/about/July 27, 2015 at 4:54 pm #160634ChristophMemberHi,
you are not calling genesis(); on the template, so all the Genesis goodness, like genesis hooks or widget areas won't be available.
If you want to stay outside of Genesis and your slider provides a short code (like soliloquy) you can include it that way on the template.
Here is an example of how Mike Hemberger is including ACF in a "genesis" template:
http://thestizmedia.com/front-end-post-editing-with-acf-pro/
July 28, 2015 at 7:00 am #160726LeaChristineMemberOk, so this is really weird, but I added
<?php genesis (); ?>
right after the
<?php /** * Template Name: About Page * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ get_header(); ?>
in my about.php, and now the slider is showing up where I want it to, but all the ACF content that was located in my entry-content is now sitting below the footer??
July 28, 2015 at 7:14 am #160730coralseaitMemberJuly 28, 2015 at 7:22 am #160731LeaChristineMemberI just cut and paste the
<?php genesis (); ?>
to the very end of my about.php, so right after the
<?php get_footer(); ?>
but now the slider and entry content is under the footer.. sorry, I guess I'm not understanding the exact way I should format the code so that the Genesis loop is included with ACF integrated into it?
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.