-1

I want to display a loop in my page-projets.php file.

<div class="loop center">

    <?php       
    if ( have_posts() ) :
        while ( have_posts() ) : the_post();
            get_template_part('content');
        endwhile;
        get_template_part('pagination');
    endif; ?>
</div>

However, on the resulting page, I can only see the page itself within the loop. Sometimes, it even returns a blank result : http://riehling.mrcoolblog.com/projets/

Could you please tell me what's wrong here ?

Regards, Greg

2 Answers 2

0

All other things being equal, your page file "page-projets.php" will display a page with a slug = "projets". So... what is the contents of that page?

3
  • That page just displays a loop. "Projets" is the term for "post" in this project, so basically this is the main loop for the website. Commented Dec 19, 2016 at 10:44
  • Well then, shouldn't your file be "single-projets.php" rather than "page-projets.php.php".
    – Tedinoz
    Commented Dec 19, 2016 at 11:18
  • Sorry, I have been confusing you. A "Projet" is a page following the single.php template, indeed. The "Projets" page is the main loop, displaying all projects. Commented Dec 19, 2016 at 13:47
0

To display a custom list of post types, you would have to write your own loop in the your page-projets.php theme file.

For example:

<div class="loop center">

    <?php
    $args = array(
        'post_type'         => '',
        'posts_per_page'    => '',
    );

    $query = new WP_Query( $args );

    if ( $query->have_posts() ) :
        while ( $query->have_posts() ) : $query->the_post();
            get_template_part('content');
        endwhile;
        get_template_part('pagination');
    endif; ?>
</div>

Replace the values for post_type and posts_per_page with your custom values.

You can also find additional parameters in the Wordpress Codex for WP_Query

2
  • OK, thank you. I now use the following code : $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args = array( 'posts_per_page'=>20, 'paged' => $paged ); $loop = new WP_Query( $args ); if ( have_posts() ) : // while ( have_posts() ) : $loop->the_post(); while ( $loop->have_posts() ) : $loop->the_post(); get_template_part('content'); endwhile; get_template_part('pagination'); endif; Commented Dec 19, 2016 at 10:42
  • But, that breaks the pagination. I cannot go to page 2 (no pagination displayed and raw URL ../page/2 sends a 404 ). Commented Dec 19, 2016 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.