Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #83431
    Deborah
    Participant

    Hi,
    I am using a child theme for Evolution Pro. I have several post categories, but I only want to display one post category on my default blog page. For example, I have a category called Tips and Tricks that users can add posts to. I have a page titled Tips and Tricks and it is set to blog template. I only want posts that have the tips and tricks category to show up on that page. I also have a news post category and will have another category as well that I do not want to show up on the Tips and Tricks blog page. I can’t seem to figure out how to make that happen. In the past, with other themes, I have just duplicated the blog template page for each individual category, but I can’t seem to figure it out this time. Can you please point me in the right direction?

    Thanks in advance.

    #83450
    Mahesh
    Keymaster

    Hi @Deborah,

    For the above, you have to create a child theme. You can find more on how to create child theme HERE. If you have set Tips and Tricks page as the blog page then creating other template won’t work. You have to create index.php in child theme to override default blog page. Following is the code for index.php.

    <?php
    // Exit if accessed directly
    if ( !defined('ABSPATH')) exit;
    
    /**
     * Template Name: Blog Template
     * Description: A Page Template that disables a blog
     *
     * @package Catch Themes
     * @subpackage Catch_Evolution_Pro
     * @since Catch Evolution Pro 1.0
     */
    
    get_header(); ?>
    
    			<?php
    			global $more, $wp_query, $post, $paged;
    			$more = 0;
    
    			if ( get_query_var( 'paged' ) ) {
    
    				$paged = get_query_var( 'paged' );
    
    			}
    			elseif ( get_query_var( 'page' ) ) {
    
    				$paged = get_query_var( 'page' );
    
    			}
    			else {
    
    				$paged = 1;
    
    			}
    
    			$blog_query = new WP_Query( array(
    				'post_type' => 'post',
    				'paged' => $paged ,
    				'category_name' => 'tips-and-tricks'
    				) );
    			$temp_query = $wp_query;
    			$wp_query = null;
    			$wp_query = $blog_query;
    
    			if ( $blog_query->have_posts() ) : ?>
    
    				<header class="page-header">
    					<h1 class="page-title"><?php the_title(); ?></h1>
    				</header>
    
    				<?php while ( $blog_query->have_posts() ) : $blog_query->the_post();  ?>
    
    					<?php
    						/* Include the Post-Format-specific template for the content.
    						 * If you want to overload this in a child theme then include a file
    						 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    						 */
    						get_template_part( 'content', get_post_format() );
    					?>
    
    				<?php endwhile; ?>
    
                    <?php catchevolution_content_nav( 'nav-below' ); ?>
    
    			<?php else : ?>
    
    				<article id="post-0" class="post no-results not-found">
    					<header class="entry-header">
    						<h1 class="entry-title"><?php _e( 'Nothing Found', 'catch-evolution' ); ?></h1>
    					</header><!-- .entry-header -->
    
    					<div class="entry-content">
    						<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'catch-evolution' ); ?></p>
    						<?php get_search_form(); ?>
    					</div><!-- .entry-content -->
    				</article><!-- #post-0 -->
    
    			<?php endif;
    			$wp_query = $temp_query;
    			wp_reset_postdata(); ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And for news and other categories, create a template file as above and then while create the page select the respective templage.

    Note: In the above code, please change the category-name to your category respective category slugs. (not id).

    Regards,
    Mahesh

    #83481
    Deborah
    Participant

    Hi Mahesh,
    Thank you for your quick response. I have copied the above code into a new index.php file in my child theme folder. I have a page titled Tips and Tricks and it is set as a blog template. I changed the category_name to ‘tips-tricks’
    which is the slug for my tips and tricks category.

    $blog_query = new WP_Query( array(
    ‘post_type’ => ‘post’,
    ‘paged’ => $paged ,
    ‘category_name’ => ‘tips-tricks’
    ) );

    However, all of the blog categories are still showing up on my Tips and Tricks page. Here is a link to the page: http://bayoucityflyersrc.com/tips-and-tricks/.

    Can you help me figure out what I might have done wrong?
    Thanks,
    Debbie

    #83653
    Mahesh
    Keymaster

    Hi @Deborah,

    Go to “Dashboard=> Appearance=> Customize=> Static Front Page” and make sure that you’ve selected Tips and Tricks page in Posts Page dropdown.

    The query in the above code is fine.

    Regards,
    Mahesh

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Limit blog page to only one category’ is closed to new replies.