WordPress.org

Ready to get started?Download WordPress

Forums

Display set amount of custom posts (4 posts)

  1. MrThunder
    Member
    Posted 1 year ago #

    Hi I am using custom post types and I wish to have show_posts=5 but I am not sure where to put the code. my knowledge of php is very basic. Thanks

    <?php query_posts( 'post_type=latestnews'); ?>
    	            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	                     <?php $currentid = get_the_id(); ?>
    	                                	<ul class="line">
    	                                		<li><a href="<?php the_permalink(); ?>"><?php echo get_the_title($currentid); ?></a></li>
    	                                	</ul>
    
    	                    <?php
    	                endwhile;
    	            endif;
    
                wp_reset_query();
                ?>
  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    on the most basic level, add it to the first line:

    <?php query_posts( 'post_type=latestnews&posts_per_page=5'); ?>

    a lot of information can be found in the Codex;

    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Class_Reference/WP_Query

  3. MrThunder
    Member
    Posted 1 year ago #

    Thanks a million that worked!

    How do I change the code so that I display the 5 posts after the most current 5? I have a page of the latest 5 posts and I wish to have the titles of the previous 5 in the sidebar.

  4. MrThunder
    Member
    Posted 1 year ago #

    Never mind I figured it out.

    <?php query_posts( 'post_type=latestnews&posts_per_page=3&offset=5'); ?>
    	            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	                     <?php $currentid = get_the_id(); ?>
    	                                	<ul class="line">
    	                                		<li><a href="<?php the_permalink(); ?>"><?php echo get_the_title($currentid); ?></a></li>
    	                                	</ul>
    
    	                    <?php
    	                endwhile;
    	            endif;
    
                wp_reset_query();
                ?>

Topic Closed

This topic has been closed to new replies.

About this Topic