WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query_posts (5 posts)

  1. Roy
    Member
    Posted 3 years ago #

    Sorry for the silly question, but can I combine

    <?php query_posts( 'post_type=blog');
     if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    with
    query_posts('posts_per_page=5');
    and if yes, how?

    My trial-and-error method failed.

    The idea is to have a different number of posts per page than the setting under "reading".

  2. DigitalSquid
    Member
    Posted 3 years ago #

    $loop = new WP_Query( array( 'post_type' => 'blog', 'posts_per_page' => 5 ) );
    while ( $loop->have_posts() ) : $loop->the_post();
  3. Roy
    Member
    Posted 3 years ago #

    Thanks, but sorry again, that does not seem to be:

    <?php $loop = new WP_Query( array( 'post_type' => 'blog', 'posts_per_page' => 5 ) );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>

    This results in a blank screen (I simply replaced the block I opened with, maybe you didn't mean that?

  4. DigitalSquid
    Member
    Posted 3 years ago #

    Strange, it worked on my blog.

    Try this instead then:

    <?php
    $args = array(
    	'posts_per_page' => 5,
    	'post_type' => 'blog'
    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    Here's the Codex page with the info: http://codex.wordpress.org/Function_Reference/query_posts

  5. Roy
    Member
    Posted 3 years ago #

    Jiha! The result is not pretty, but it (temporarily) patches a problem.
    Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.