Support » Fixing WordPress » Custom Template for Specific Category

  • Resolved astromono


    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?

    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(); ?>
    			<?php edit_post_link('Edit this entry.', '<p style="border-top:1px dotted #999;padding-top:6px;margin-top:10px;">', '</p>'); ?>
    	<div class="wpn_box-bottom"></div>
    	<!-- Comments // -->
    			/* 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; ?>
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • 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

    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);
    <?php endforeach; ?>

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

    Hello astromono,

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Template for Specific Category’ is closed to new replies.