Community Forums › Forums › Archived Forums › General Discussion › Want only one category to show up on Blog
Tagged: one category on blog
- This topic has 10 replies, 2 voices, and was last updated 11 years ago by Ben Siegfried.
-
AuthorPosts
-
March 30, 2013 at 2:50 pm #32135Ben SiegfriedMember
How do I get only one category to show up on the Blog?
March 30, 2013 at 3:45 pm #32137RobinMemberGenerally, I use the blog template for the page template, and add a custom field:
Name is query_args
Value is cat=xx (xx being the ID number of your desired category)HTH
I do the best I can with what I’ve got. (say hey on twitter)
March 30, 2013 at 3:48 pm #32139Ben SiegfriedMemberI'm wanting to do this with the Agency's home page, altering the home.php file. I've already gotten the blog to show under the slider. Will this method you are suggesting with the arg code work the way I have it? I have no idea how the code string should actually look.
March 30, 2013 at 7:00 pm #32162RobinMemberThe query_args works as a custom field in a blog page template. If you've already modified the home.php then it's hard to know what you need to do to show only one category without seeing that code. You can post it here (and a link to your site would probably help, too, but to see what is going on with the php, we need to see it).
I do the best I can with what I’ve got. (say hey on twitter)
March 30, 2013 at 7:13 pm #32164Ben SiegfriedMemberI appreciate your help.
http://www.siegfriedmedia.com/rivasrocks is the site. I have some stand-in posts, they are two categories. I want only one of the categories to show.
Here's the home.php code:
add_action( 'genesis_meta', 'agency_home_genesis_meta' ); /** * Add widget support for homepage. If no widgets active, display the default loop. * */ function agency_home_genesis_meta() { if ( is_active_sidebar( 'home-welcome' ) || is_active_sidebar( 'home-slider' ) || is_active_sidebar( 'home-left' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-right' ) ) { //remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_after_header', 'agency_home_welcome_helper' ); //add_action( 'genesis_loop', 'agency_home_loop_helper' ); //add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); add_filter( 'body_class', 'add_body_class' ); function add_body_class( $classes ) { $classes[] = 'agency'; return $classes; } } } function agency_home_welcome_helper() { if ( is_active_sidebar( 'home-slider' ) ) { echo '<div id="home-slider">'; dynamic_sidebar( 'home-slider' ); echo '</div><!-- end #home-slider -->'; } if ( is_active_sidebar( 'home-welcome' ) ) { echo '<div id="home-welcome">'; dynamic_sidebar( 'home-welcome' ); echo '</div><!-- end #home-welcome -->'; } } function agency_home_loop_helper() { if ( is_active_sidebar( 'home-left' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-right' ) ) { echo '<div id="home">'; echo '<div class="home-left">'; dynamic_sidebar( 'home-left' ); echo '</div><!-- end .home-left -->'; echo '<div class="home-middle">'; dynamic_sidebar( 'home-middle' ); echo '</div><!-- end .home-middle -->'; echo '<div class="home-right">'; dynamic_sidebar( 'home-right' ); echo '</div><!-- end .home-right -->'; echo '</div><!-- end #home -->'; } } genesis();
March 31, 2013 at 7:29 am #32247RobinMemberHmmmmm...this is not something I've done before. But try doing the first example from this post? You'll want to uncomment your remove_action for the genesis loop because you'll be replacing the genesis standard loop with your own custom one.
I do the best I can with what I’ve got. (say hey on twitter)
March 31, 2013 at 9:00 am #32253Ben SiegfriedMemberYah, but can I have the same arrangement with slider above the blog and have that be the homepage, I guess, not even using the home.php page at all, but having this template page be the homepage?
March 31, 2013 at 1:54 pm #32313Ben SiegfriedMemberRobin,
In the Genesis Theme Settings panel you can choose display/exclude by a single category and/or exclude by post ID but this only works on the Blog page. It worked but only for the Blog page. I need it for the home.php page where I have posts showing under the responsive slider.
I'd use the Blog page as the homepage of my site if I could know how to make the main URL not bring up the home.php page and also be able to install the responsive slider above the blog posts on the Blog page.
March 31, 2013 at 5:50 pm #32362Ben SiegfriedMemberUsing the WP query code here in Bill's tutorial (http://www.billerickson.net/customize-the-wordpress-query/), what code would I add into my home.php (code below) to exclude a category or post IDs? Bill Erickson's code is shown to go into the functions.php file but that didn't seem to work for what I'm trying, or maybe I did it wrong. I don't understand enough about php to figure out what to do with the query code.
add_action( 'genesis_meta' , 'agency_home_genesis_meta' ); /** * Add widget support for homepage. If no widgets active, display the default loop. * */ function agency_home_genesis_meta() { if ( is_active_sidebar( 'home-welcome' ) || is_active_sidebar( 'home-slider' ) || is_active_sidebar( 'home-left' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-right' ) ) { //remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_after_header' , 'agency_home_welcome_helper' ); //add_action( 'genesis_loop', 'agency_home_loop_helper' ); //add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); add_filter( 'body_class' , 'add_body_class' ); function add_body_class( $classes ) { $classes [] = 'agency' ; return $classes ; } } } function agency_home_welcome_helper() { if ( is_active_sidebar( 'home-slider' ) ) { echo ' <div id="home-slider">'</div> ; dynamic_sidebar( 'home-slider' ); echo ' <!-- end #home-slider -->' ; } if ( is_active_sidebar( 'home-welcome' ) ) { echo ' <div id="home-welcome">'</div> ; dynamic_sidebar( 'home-welcome' ); echo ' <!-- end #home-welcome -->' ; } } function agency_home_loop_helper() { if ( is_active_sidebar( 'home-left' ) || is_active_sidebar( 'home-middle' ) || is_active_sidebar( 'home-right' ) ) { echo ' <div id="home">'</div> ; echo ' <div class="home-left">'</div> ; dynamic_sidebar( 'home-left' ); echo ' <!-- end .home-left -->' ; echo ' <div class="home-middle">'</div> ; dynamic_sidebar( 'home-middle' ); echo ' <!-- end .home-middle -->' ; echo ' <div class="home-right">'</div> ; dynamic_sidebar( 'home-right' ); echo ' <!-- end .home-right -->' ; echo ' <!-- end #home -->' ; } } genesis();
March 31, 2013 at 6:16 pm #32366RobinMemberWell, Bill Erickson is a major guru, so things he says are worth paying attention to. His function seems pretty straightforward--did you check the category ID number to make sure that was correct? His goes in the functions.php file so you shouldn't mess with the home.php to use it. I think.
Otherwise, you could try modifying your home.php that you posted, starting with this line:
/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );function child_do_custom_loop() {
global $paged; // current paginated page
global $query_args; // grab the current wp_query() args
$args = array(
'category__not_in' => 42, // exclude posts from this category
'paged' => $paged, // respect pagination
);genesis_custom_loop( wp_parse_args($query_args, $args) );
}
and change 42 to whatever your category number is.Another option, if you don't necessarily want to use the home.php template, is to remove it from the situation altogether (just rename it to home.php.old for starters if you want to change your mind). You could use a static page running the blog template as your home page and do query_args in a custom field, but you would have to figure out how to handle the slider in that situation. I don't think it's the right solution for what you probably want to do.
I do the best I can with what I’ve got. (say hey on twitter)
March 31, 2013 at 6:22 pm #32367Ben SiegfriedMemberThanks Robin, I see what points you are making. At first when I tried Bill's code I was using the post IDs and not the cat IDs. I got it to work excluding the category I wanted using the cat ID, using the code below in the functions.php file.
<code>
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
/**
* Exclude Category from Blog
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_exclude_category_from_blog( $query ) {if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'cat', '-4' );
}}
</code>This http://www.wordpress.org/extend/plugins/display-posts-shortcode/ also works very well. I played around with it for a while, but wouldn't work in my situation because I'm altering the home.php file.
-
AuthorPosts
- The topic ‘Want only one category to show up on Blog’ is closed to new replies.