1

My front page displays the latest posts using index.php.

My page.php contains the wp_header up top, the wp_footer below, and this in between:

while (have_posts()) : the_post();
    get_template_part( 'content', 'page' );
endwhile;

My content-page.php is supposed to print out the_content() and the the_title() of the page, but it returns the content and title of all the posts. What am I missing?

The page is set to 'Default Template'.

I've added my page.php and content-page.php below:

page.php:

<?php /* Page */ ?>
<?php get_header(); ?>
    <div class="container-fluid">
        <div class="container">
            <?php while (have_posts()) : the_post();
                      get_template_part( 'content', 'page' );
                  endwhile; ?>
        </div>
    </div>
<?php get_footer(); ?>

content-page.php

<?php /* The template used for displaying page content in page.php */ ?>
<?php
  echo '<div class="row">';
    echo '<div class="col-sm-12">';
      echo the_title( '<h2>', '</h2>');
      echo '<p>' . the_content() . '</p>';
    echo '</div>';
  echo '</div>';
?>

index.php

<?php /* Main file */ ?>

<?php get_header(); ?>

<div class="container-fluid">
  <div class="container">
    <?php
      if(have_posts()) :
        while (have_posts()) : the_post();
          echo '<div class="row';
          if($count > 2){
            echo ' hideme';
          }
          echo '">';
            echo '<div id="section-'. $count++ .'" class="col-sm-12" style="text-align:center;">';
              echo '<p><a href="' . get_permalink( get_the_ID() ) . '">';
              echo the_post_thumbnail();
              echo '<br>' . get_the_title() . ' // ' . get_the_category_list(', ') . '</a></p>';
            echo '</div>';
          echo '</div>';
        endwhile;
      endif;
    ?>
  </div>
</div>

<?php get_footer(); ?>
  • 1
    With so little information it is hard to even hazard a guess. We'd really need to see the rest of the page.php template but this sounds like someone is using query_posts somewhere or the wrong template is being used to display the page in question. – Privateer Feb 9 '15 at 23:09
  • If you can echo the query ( global $wp_query; echo '<pre>' . print_r( $wp_query, true ) . '</pre>'; and post that up in the main section, someone might be able to point out at least what the problem is. Also, you might edit your post to include the full page rather than putting it in comments =) – Privateer Feb 10 '15 at 15:19
  • @Sultenhest Pease add all your code in your question via an edit. Do not add code in comments, it is hard to read and most people ignore comments. So add your code where it is supposed to be inside* your question :-) – Pieter Goosen Feb 10 '15 at 18:16
  • @Privateer + Pieter, I did so now :) Here's a link where you can check out the query [sultenhest.dk/zip ] – Sultenhest Feb 10 '15 at 18:18
  • 1
    Can you confirm is it page.php and content-page.php and not Page.php and Content-page.php? Capital letters and lower case letters are not the same. Also have you used query_posts anywhere in your code? – Tom J Nowell Feb 10 '15 at 18:19
1

From your query (noted in the comments above), the page you are looking at believes that it is your home page (e.g. your blog).

Notice in the wp_query object the following

[found_posts] => 8
[is_home] => 1

is_home signifies that it believes that it is showing the home page.

If your files are set up as you say, you should check your admin panel under Settings > Reading and make sure that the page you are viewing is not set up as your "Posts Page" under the Front Page Displays section.

If that is not the case then noting what your index.php and/or home.php files contain might be helpful ... as the page you are viewing definitely believes itself to be your home / blog page.

  • Okay. I've added my index.php to my question now. Would leaving index.php empty and copying that code to a new template called 'content-home.php' (or something like that), maybe help solve the problem? – Sultenhest Feb 10 '15 at 19:26
  • Did you check your reading settings? If not, check them before anything else. – Privateer Feb 10 '15 at 21:04
  • Yeah, it's set to 'Frontpage Displays: Your latest posts'. – Sultenhest Feb 11 '15 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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