WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Template for Specific Category (4 posts)

  1. astromono
    Member
    Posted 3 years ago #

    Hey there guys, I've been tryin' to get this right for a few hours, but I guess I'm not that good at custom templates.

    How would I go about making this page template show posts from only one specific category? As if it were a loop?

    <?php
    /*
    Template Name: No Sidebar Template
    */

    get_header(); ?>

    <div class="left left_fullwidth">
    	<div class="articles article">
    		<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<h1 class="title"><?php the_title(); ?></h1>
    			<div class="post">
    				<?php the_content(); ?>
    			</div>
    			<?php edit_post_link('Edit this entry.', '<p style="border-top:1px dotted #999;padding-top:6px;margin-top:10px;">', '</p>'); ?>
    	</div>
    	<div class="wpn_box-bottom"></div>
    
    	<!-- Comments // -->
    		<?php
    			/* Remove the // below to enable comments on pages */
    			// comments_template();
    		?>
    	<!-- // Comments -->
    	<div class="wpn_clear"></div>
    
    		<?php endwhile; ?>
    	<?php else : ?>
    		<?php include ('editable/404/404-error.php'); ?>
    	<?php endif; ?>
    </div>
    <?php get_footer(); ?>
  2. MULTIDOTS
    Member
    Posted 3 years ago #

    Hi astromono,

    You can show posts from specific category by adding

    query_posts($query_string . 'category_name=MULTIDOTS');

    line of code after
    <?php if (have_posts()) : ?>

    where MULTIDOTS is the name of the category, you can put your category name and it will show posts with that specific category.

    Ask me again if any query

  3. astromono
    Member
    Posted 3 years ago #

    Thanks so much for the info!

    I actually managed to display the loop for the specific category by doing this:

    <div class="left">
    	<ul class="articles">
    		<?php if (have_posts()) : ?>
    
    		<?php $thePosts = get_posts('category=13510');
    foreach($thePosts as $post) : setup_postdata($post);
    ?>
    
    LOOP INFO HERE
    
    <?php endforeach; ?>

    Problem is, now I can't seem to get pagination working properly for it. Help anyone?

  4. MULTIDOTS
    Member
    Posted 3 years ago #

    Hello astromono,

    For that purpose you can refer correct-pagination-with-get_posts

Topic Closed

This topic has been closed to new replies.

About this Topic