Community Forums › Forums › Archived Forums › Design Tips and Tricks › How Can I Hook a Widget Area on Just the Blog Page?
Tagged: blog page, hook, widget area
- This topic has 4 replies, 2 voices, and was last updated 9 years, 7 months ago by
Kabolobari.
-
AuthorPosts
-
September 15, 2015 at 4:51 pm #165639
Kabolobari
MemberHi, can someone help?
I'm trying to hook a widget area to show just on the main blog archive page, but not on other pages or single post areas.
I have used the following codes:
//* Register Blog Page After Header Widget Area
genesis_register_sidebar( array(
'id' => 'bp-after-header',
'name' => __( 'Blog Page After Header', 'wintersong' ),
'description' => __( 'Place stuff here to show before post on blog page', 'wintersong' ),
) );//* Hook Blog Page After Header Widget Area
add_action( 'genesis_after_header', 'add_bp_after_header' );
function add_bp_after_header() {
if ( is_page( 'blog' ) )
genesis_widget_area( 'bp-after-header', array(
'before' => '<div class="bp-after-header widget-area">',
'after' => '</div>',
) );
}But while I can see the widget area within my dashboard on the widget section, meaning it registered, I cannot see anything I place in it on the live site (front-end). I guess it has to do with the 'hooking' code. Since I have a very poor understanding of PHP/WordPress, could someone help look at it and correct?
Thanks a great deal.
PS. I've done something similar on this page, but it's a category page and I can't seem to replicate it: http://kabolobari.com/book.
KB
September 15, 2015 at 5:22 pm #165644Victor Font
ModeratorIt's most likely your use of is_page(). The is_page() function with a text argument ('blog') is looking for a post on the page with the title or slug of blog. If you want to reference the page itself, you have to use the page id: is_page( 10 ). You can learn more about the function here: https://codex.wordpress.org/Function_Reference/is_page
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?September 16, 2015 at 2:04 am #165701Kabolobari
MemberThanks very much, Victor Front. Is this what you mean?
if ( is_page( '79' ) )
Now, did you help me check, are other lines correct except this one? Because I'm gonna try this option and see if it ouputs to the blog page.
Thanks.
KB
September 16, 2015 at 2:19 am #165708Kabolobari
MemberHi, Victor Font, see I've just tried this and still don't see it output!
//* Hook Blog Page After Header Widget Area add_action( 'genesis_after_header', 'add_bp_after_header' ); function add_bp_after_header() { if ( is_page( '79' ) ) genesis_widget_area( 'bp-after-header', array( 'before' => '<div class="bp-after-header widget-area">', 'after' => '</div>', ) ); }
I used this code:
//* Create Custom Category Archive Widget Area genesis_register_sidebar( array( 'id' => 'book-category-widget', 'name' => __( 'Book Category Widget', 'wintersong' ), 'description' => __( 'This is the widget section for the Book Category Page.', 'wintersong' ), ) ); //* Hook Category Widget Area Before Post Content add_action( 'genesis_before_content', 'wintersong_category_archive_widget' ); function wintersong_category_archive_widget() { if ( is_category(38) ) genesis_widget_area( 'book-category-widget', array( 'before' => '<div class="book-category-widget widget-area">', 'after' => '</div>', ) ); }
However, notice similar code won't work for the blog archive:
I hope you understand what I mean and can just help with the right code. Thanks.
Thanks.
KB
September 16, 2015 at 2:29 am #165710Kabolobari
MemberHi, Victor Font, here's too Dropbox links to the screenshots I referenced in my response above. I notice the images did not display:
1. Category Page (kabolobari.com/book): https://www.dropbox.com/s/gm8lmjvvet9svzi/kabolobari-book.jpg?dl=0
2. Blog Page (kabolobari.com/blog): https://www.dropbox.com/s/vna0oos3fwuxuwg/kabolobari-blog.jpg?dl=0Thanks.
KB
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.