Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding Featured Posts widget areas to a static page
Tagged: adding widget areas, featured posts, Static Page
- This topic has 31 replies, 2 voices, and was last updated 11 years, 3 months ago by
nutsandbolts.
-
AuthorPosts
-
November 7, 2013 at 6:32 pm #71575
Ben Siegfried
ParticipantIs it possible to add the Featured Posts Widget areas to a static page that has a sidebar-right (for example)?
I know how to add them to the sidebar, I want to know if it's possible to add them to the static page that has a sidebar.
November 7, 2013 at 6:54 pm #71578nutsandbolts
MemberYou could do that by adding a widget area to show up on pages (or a specific page, depending on what conditionals you use). You can hook the widget area just like you would for the homepage, but the code goes in functions.php. Hope that helps!
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 7, 2013 at 9:19 pm #71614Ben Siegfried
ParticipantI don't know how to do that off the top of my head. Do you know of any tuts or snippets that could lead me down the path?
I've manipulated homepages a bit and can get a widget area to register, just not sure how to do a specific page I have. It would be Client List page I want to use featured posts widget to insert their logos.
November 8, 2013 at 12:34 am #71630nutsandbolts
MemberYou would register the widget area in functions.php just like one for the homepage, but then you'd need a function to show it on the individual page.
So let's say you called the widget area Page Bottom (because that's what I've got handy - hahaha). Here's what you would need in functions if you're using an XHTML child theme - if it's one of the new HTML5 themes, let me know and I'll give you a different hook. (And if you want it somewhere other than the bottom of the page content, you'll need a different hook anyway.)
//* Register the page bottom widget area genesis_register_sidebar( array( 'id' => 'page-bottom', 'name' => __( 'Page Bottom', 'nabm' ), 'description' => __( 'This is the widget area at the bottom of a certain page.', 'nabm' ), ) ); //* Add the page bottom widget after the page content add_action( 'genesis_after_post_content', 'nabm_add_page_bottom' ); function nabm_add_page_bottom() { if ( is_page() ) genesis_widget_area( 'page-bottom', array( 'before' => '<div id="page-bottom">', ) ); }
On the second snippet, pay close attention to
if ( is_page() )
because you'll need to add the page ID. You can find that by going to Pages > All Pages and hovering over the edit link for the page - you'll see an ID number in the edit URL.If the page ID is 348, you'll use
if ( is_page(348) )
to make it show on that page only. Hopefully that makes sense!You'll also need to add some CSS to make the widget area look right. Here's some that should help, though you may need to tweak it or add to it for your particular theme:
/* Page Bottom ------------------------------------------------------------ */ #page-bottom { line-height: 1.5; padding: 32px; padding: 2rem; } #page-bottom p { margin-bottom: 24px; margin-bottom: 1.5rem; text-align: center; }
Hope that helps you get started!
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 9:04 am #71673Ben Siegfried
ParticipantThank you so much!
I'm using Agency-Pro, if you would share the other hook that would help more, other than that I believe I can apply what you're sharing to what I need to do.
November 8, 2013 at 10:03 am #71686nutsandbolts
MemberOkay, replace this part:
//* Add the page bottom widget after the page content add_action( 'genesis_after_post_content', 'nabm_add_page_bottom' ); function nabm_add_page_bottom() { if ( is_page() ) genesis_widget_area( 'page-bottom', array( 'before' => '<div id="page-bottom">', ) ); }
with this:
//* Add the page bottom widget after the page content add_action( 'genesis_entry_footer', 'nabm_add_page_bottom' ); function nabm_add_page_bottom() { if ( is_page() ) genesis_widget_area( 'page-bottom', array( 'before' => '<div id="page-bottom">', ) ); }
Everything else should be the same.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 12:50 pm #71732Ben Siegfried
ParticipantWhat is "nabm_add_page_bottom," is that a naming convention you created or a Genesis/WordPress naming convention?
November 8, 2013 at 12:51 pm #71733nutsandbolts
MemberThat's just the name I used for the function - I usually put "nabm" at the beginning of the functions I write (stands for Nuts and Bolts Media), but you can name your functions anything you'd like. You could call it
i_like_pie
and it would work the same way as long as you used the same name in both places.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:09 pm #71737Ben Siegfried
ParticipantOk, here's what I have and a parse error comes up for line 126, which is this one
add_action( 'genesis_entry_content (HTML5)', 'agency_add_page_content' );
I think I may have this
'agency_add_page_content'
wrong?Here's the full code:
//* Register the page widget area genesis_register_sidebar( array( 'id' => 'partial-client-list', 'name' => __( 'Partial Client List', 'agency' ), 'description' => __( 'This is the widget area in the content of a certain page.', 'agency' ), //* Add the page widget in the content add_action( 'genesis_entry_content (HTML5)', 'agency_add_page_content' ); function agency_add_page_content() { if ( is_page(94) ) genesis_widget_area( 'partial-client-list', array( 'before' => '<div id="partial-client-list">', ) ); }
November 8, 2013 at 1:12 pm #71738nutsandbolts
MemberIt's the HTML5 in parentheses - that shouldn't be there. The action should look like this:
add_action( 'genesis_entry_content', 'agency_add_page_content' );
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:16 pm #71740Ben Siegfried
ParticipantRemoved HTML5 in parenthesis and it still parses an error for
add_action( 'genesis_entry_content', 'agency_add_page_content' );
November 8, 2013 at 1:18 pm #71742Ben Siegfried
ParticipantOh, the hook I chose is for a "loop block," a static page is outside of the loop, not part of the loop right? If that is the case I should choose a different hook. I want to hook into the content of the page or have the widget areas appear in the page.
November 8, 2013 at 1:19 pm #71743nutsandbolts
MemberIt may not like the entry_content hook - where exactly do you want this widget area to appear?
Edited to add: Looks like we had the same thought at the same time.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:20 pm #71745nutsandbolts
MemberWhere in the page? After the page content? Before the page content? Positioning is key.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:24 pm #71750Ben Siegfried
ParticipantMaybe this one? I am working in Agency-Pro though, not sure if this would work.
genesis_post_content (XHTML) This hook outputs the actual post content and if chosen, the post image (inside the #content div).
I want the widget area to pull in featured posts in a page's (not post) content area; I have a sidebar right (not where I want the widget area to pull in featured posts).
November 8, 2013 at 1:29 pm #71751nutsandbolts
MemberNo, that one won't work since it's XHTML.
I would try genesis_entry_footer (for after the page content) and then just not include any page content.
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:34 pm #71753Ben Siegfried
ParticipantJust tried this:
add_action( 'genesis_entry_footer', 'agency_add_page_content' );
and it still give an error for this line.The page ID is correct, I always use a widget that displays them.
November 8, 2013 at 1:36 pm #71755nutsandbolts
MemberWhat is the exact error you're getting?
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:37 pm #71756nutsandbolts
MemberAlso, what have you got in place for the entire set of functions, both to register the widget area and to display it?
Andrea Whitmer, Owner/Developer, Nuts and Bolts Media
I provide development and training services for designers • Find me on Twitter and Google+November 8, 2013 at 1:39 pm #71757Ben Siegfried
ParticipantParse error: syntax error, unexpected ';', expecting ')' in C:\Users\GRAPHICS\Documents\Websites\KPC\www.mywebsite.dev\wp-content\themes\agency-pro\functions.php on line 126
-
AuthorPosts
- The topic ‘Adding Featured Posts widget areas to a static page’ is closed to new replies.