• Resolved jimscheel

    (@jimscheel)


    Hi

    How do I creat a page template that show post from a specific category?

    I have tried with the wp_query command, but the problem is, that the navigation (Next Page and Past Page) doesn’t work proberly.

    How do i make this?

    /Jimbo

Viewing 7 replies - 1 through 7 (of 7 total)
  • Replace this:

    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>

    with this:

    <?php $numposts = get_option('posts_per_page'); ?>
    <?php $wp_query = new WP_Query('showposts='.$numposts.'&paged='.$paged); ?>
    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>

    Leave everything else the same, and use the new WP_Query(...) object to filter by category (along with the showposts and paged options).

    Thread Starter jimscheel

    (@jimscheel)

    Thanks for the fast reply I will try it right away 😉

    Thread Starter jimscheel

    (@jimscheel)

    hmmm it doesnt work

    <?php get_header(); ?>
    
    <?php $numposts = get_option('posts_per_page'); ?>
    <?php $wp_query = new WP_Query('showposts=3'.$numposts.'&paged='.$paged); ?>
    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<div class="post-header">
            <div class="date"> <?php the_time('M j') ?> <span><?php the_time('y') ?></span></div>
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <div class="author">by <?php the_author() ?></div>
          </div><!--end post header-->
    			<div class="entry clear">
    				<?php the_content('read more...'); ?>
            <?php edit_post_link('Edit This','<p>','</p>'); ?>
    			</div><!--end entry-->
          <div class="post-footer">
            <div class="comments"><?php comments_popup_link('Leave a comment', '1 Comment', '% Comments'); ?></div>
          </div><!--end post footer-->
    		</div><!--end post-->
    		<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
    		<div class="navigation index">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div><!--end navigation-->
    		<?php else : ?>
    		<?php endif; ?>
    	</div><!--end content-->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Thread Starter jimscheel

    (@jimscheel)

    got it!!

    <?php $wp_query = new wp_Query('cat=3&showposts='.$numposts.'&paged='.$paged); ?>

    Once again thanks for the help!

    Could one of you explain this in a detailed step by step for us total noobs?

    Nnyan,
    What exactly do you not understand?

    I actually figured it out but thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Creating a template thas shows post from a specify category’ is closed to new replies.