Community Forums › Forums › Archived Forums › Design Tips and Tricks › Registered widget not showing up on page template
Tagged: Page Templates, registering widget area, widgets
- This topic has 11 replies, 3 voices, and was last updated 9 years, 7 months ago by WhiteleyDesigns.
-
AuthorPosts
-
March 9, 2015 at 10:35 am #143813bibliofilleMember
Hello! I created a child theme to edit the main Genesis framework for a site I'm building.
I registered 4 different widget areas, one for each new page template I created. I successfully registered each widget, and one shows up correctly on the page template, but the other three do not. I followed the same method for all 4, so I'm not sure what I'm missing.
Here's how I registered the widget, in functions.php:
//* Register widget areas genesis_register_sidebar( array( 'id' => 'sidebar-about', 'name' => __( 'About Sidebar', 'kim-schwede' ), 'description' => __( 'This is a widget area for the about page.', 'kim-schwede' ), ) );
Here's the sidebar-about.php include file I created:
<?php /** * * @package Kim Schwede * */ <div class="sidebar widget-area"></div> genesis_structural_wrap( ‘sidebar’ ); do_action( ‘genesis_before_sidebar_widget_area’ ); dynamic_sidebar(‘sidebar-about’); do_action( ‘genesis_after_sidebar_widget_area’ ); genesis_structural_wrap( ‘sidebar’, ‘close’ ); ?> </div>
Here's what I put in the page-about.php page template, just after "get_header":<?php dynamic_sidebar( 'sidebar-about' ); ?>
I did all this and it worked fine. Then I replicated the same method to create a widget for the page-design.php template. The widget is registered, however, the content doesn't show up on the page template. I changed everything that was "sidebar-about" to "sidebar-design" and put
<?php dynamic_sidebar( 'sidebar-design' ); ?>
in the page template, but it won't show up.Any help would be much appreciated!
March 9, 2015 at 5:43 pm #143850Brad DaltonParticipantThats not really the best code to use. This is how i do it http://wpsites.net/web-design/widget-genesis/
You can call the widget from each template
or
Call them using conditional tags from your functions file:
Example:
if ( is_page_template('your-template-name'))
March 9, 2015 at 7:02 pm #143856bibliofilleMemberI got it to work by changing the template file names; I was messing up the template hierarchy.
What's wrong with the method I was using? I ask because I'm a new developer and still learning the best way to do things.
March 9, 2015 at 7:18 pm #143860WhiteleyDesignsMemberMaybe post the entire code from your page templates so we can see it. As Brad describes, you shouldn't need an about-sidebar.php based on what you're describing since you're pulling in a registered widget directly in the page template.
Or as Brad described...you should include the sidebar.php file, but inside of that wrap each widget call in a conditional statement to pull based on the page template.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 9, 2015 at 9:24 pm #143875bibliofilleMemberHere's what's in the about page template, called "page-about.php":
<?php /** * Template Name: About Page * * A custom page template for the about page. * * @package Kim_Schwede */ get_header(); ?> <?php dynamic_sidebar( 'sidebar-about' ); ?> <?php genesis(); ?> <?php get_footer(); ?>
March 11, 2015 at 7:56 am #144004WhiteleyDesignsMemberSo do you have a design page template as well (like page-design.php)? It should look something like this:
<?php /** * Template Name: Design Page * * A custom page template for the about page. * * @package Kim_Schwede */ get_header(); ?> <?php dynamic_sidebar( 'sidebar-design' ); ?> <?php genesis(); ?> <?php get_footer(); ?>
And then, of course, you would need to select that page template when editing the page in WordPress.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 11, 2015 at 8:49 am #144008bibliofilleMemberYes, that's correct. I actually had to change "page-design.php" to just "design.php". And I have a page template for a reviews page that's saved as "reviews.php". It didn't work when I had it saved as "page-reviews.php".
So you're saying that I can either call the sidebar directly in the page template or have a "sidebar.php" file and call it in "functions.php" with a conditional, but I don't need to do both?
March 11, 2015 at 9:26 am #144010WhiteleyDesignsMemberHmm...that's a bit odd that you had to change the page names to get it to work - that shouldn't make a difference.
Anyhow, yes, you'll want to call the sidebar directly in the page template OR you'll want to use the sidebar.php and use conditionals. You'll need to include the sidebar.php file in the page template somewhere, then in the sidebar.php you can use conditionals based on what you want to show on specific page templates.
I hope that makes sense...
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 11, 2015 at 9:34 am #144015bibliofilleMemberYes, that does make sense! Thanks for clarifying!
I read in the Codex that naming a page template "page-xyz" causes WordPress to view it as a specialized page template.
Here is the link: It's under the section "File Names."
I took this to mean that I couldn't have "page-about.php", "page-design.php", "page-reviews.php", etc in my child theme directory. That seemed to be true because when I did it that way, WP recognized that there was a custom page template, but wouldn't use it when I selected it from the page WYSIWYG editor.
I actually kept "page-about.php" but changed everything else to "design.php" and so forth and it worked, so that must have had something to do with it.
March 11, 2015 at 9:35 am #144016bibliofilleMemberMarch 11, 2015 at 9:36 am #144017bibliofilleMemberOk, here's the link: http://codex.wordpress.org/Page_Templates#Specialized_Page_Template
March 11, 2015 at 9:42 am #144018WhiteleyDesignsMemberAhh...I always use page_customname.php - I use an underscore, not a hyphen. That makes sense. Same as when I do a custom archive or single page is is always single-customname.php or archive-customname.php.
So - if you want to have the word page in front you could use an underscore instead and do page_design.php.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPress -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.