• I am trying to show posts from category Recipes I am getting error ,I think ,I have done right depending on my knowledge ,below is the code ,I am using query to get posts from categories and looping it through the loop and showing it

    <?php /* Template Name: Recipes Page */ ?>
    
    <?php get_header('custom1'); ?>
    
    <?php
    $homepageLayout = get_theme_mod('homepageLayout', 'no-sidebar');
    
    ?>
    
    <div class="container pm-containerPadding-top-110 pm-containerPadding-bottom-90">
        <div class="row">
    
    		<?php if($homepageLayout === 'no-sidebar') { ?>
    
            	<div class="col-lg-12 col-md-12 col-sm-12">
    
    				<?php
    
    $query = new WP_Query( 'category_name=Recipes' );
    
     if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post()); ?>
    
                        <?php get_template_part( 'content', 'post' ); ?>
    
                    <?php }//end of posts ?>
    
                    <?php } else { ?>
                         <p><?php _e('No posts were found.', 'medicallinktheme'); ?></p>
                    <?php } ?> 
    
                    <?php get_template_part( 'content', 'pagination' ); ?>
    
                </div>
    
            <?php } else if($homepageLayout === 'right-sidebar') {?>
    
                <!-- Retrive right sidebar post template -->
                <div class="col-lg-8 col-md-8 col-sm-12">
    
    				<?php
    
    $query = new WP_Query( 'category_name=Recipes' );
    
     if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post()); ?>
    
                        <?php get_template_part( 'content', 'post' ); ?>
    
                    <?php }//end of posts ?>
    
                    <?php } else { ?>
                         <p><?php _e('No posts were found.', 'medicallinktheme'); ?></p>
                    <?php } ?> 
    
                    <?php get_template_part( 'content', 'pagination' ); ?>
    
                </div>
    
                 <!-- Right Sidebar -->
                 <?php get_sidebar('home'); ?>
                 <!-- /Right Sidebar -->
    
            <?php } else if($homepageLayout === 'left-sidebar') { ?>
    
            	 <!-- Left Sidebar -->
                 <?php get_sidebar('home'); ?>
                 <!-- /Left Sidebar -->
    
                <!-- Retrive right sidebar post template -->
                <div class="col-lg-8 col-md-8 col-sm-12">
    
    				<?php
    
    $query = new WP_Query( 'category_name=Recipes' );
    
     if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post()); ?>
    
                        <?php get_template_part( 'content', 'post' ); ?>
    
                    <?php }//end of posts ?>
    
                    <?php } else { ?>
                         <p><?php _e('No posts were found.', 'medicallinktheme'); ?></p>
                    <?php } ?> 
    
                    <?php get_template_part( 'content', 'pagination' ); ?>
    
                </div>
    
            <?php } else {//default full width layout ?>
    
            	<div class="col-lg-12 col-md-12 col-sm-12">
    
    				<?php
    
    $query = new WP_Query( 'category_name=Recipes' );
    
     if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post()); ?>
    
                        <?php get_template_part( 'content', 'post' ); ?>
    
                    <?php }//end of posts ?>
    
                    <?php } else { ?>
                         <p><?php _e('No posts were found.', 'medicallinktheme'); ?></p>
                    <?php } ?> 
    
                    <?php get_template_part( 'content', 'pagination' ); ?>
    
                </div>
    
            <?php }  ?>
    
    	</div> <!-- /row -->
    </div> <!-- /container -->
    <?php get_footer(); ?>
  • The topic ‘creating custom template in wordpress to show category posts’ is closed to new replies.