• flow01

    (@flow01)


    I’ve got two following problems with WordPress:

    • I create template-test.php file. I put there The Loop (it should show 10 posts – it’s exactly the same The Loop like in index.php). Then I create a Page that is using this template and I don’t see 10 posts but one post and it’s not actually a post but a page linking to itself (I see page title + excerpt below it with post’s style). I don’t know why it happens but if I put EXACTLY the same code in index.php and template-test.php why do I get different output?
    • The file above only works if I set permalinks to %category%/%postname%/ (or something like this). If I use standard links index.php works fine and shows 10 posts but custom page template show 404 Error.

    Any help would be great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    Try using a new query:

    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 10,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter flow01

    (@flow01)

    Your new query works great!

    Could you tell me please why old query returns only one link that’s pointing to the page that is currently displayed?

    I guess that your new query will work with all types of links so that would solve my second problem too. Why the old one returns 404 page?

    MichaelH

    (@michaelh)

    The other query is ‘automatically’ populated by WordPress and normally you should use a new query if you are imposing new query requirements.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘The Loop doesn’t work on page templates’ is closed to new replies.