admin管理员组

文章数量:1192814

I am using HTML5 Blank to make my site. I wanted to style some pages differently than others, and therefore made a page template for them. In this page template I have used this to get the content:

<?php the_content(); ?>

This worked perfectly yesterday. Then I woke up today and now the same pages show this error and no content:

Warning: count(): Parameter must be an array or an object that implements Countable in /home/insitvbt/treningsglad/wp-includes/post-template.php on line 317

Everything else in the page template file loads fine, just not the content. I can't see anything in the logs about any updates happening from yesterday until today, so this perplexes me a bit.

These are the lines around 317 in post-template.php:

// If the requested page doesn't exist.
Line 317 ---> if ( $elements['page'] > count( $elements['pages'] ) ) {
    // Give them the highest numbered page that DOES exist.
    $elements['page'] = count( $elements['pages'] );
}

I have Googled for about an hour and find many people with the same type of problem, but no apparent solution to my exact case. I have disabled all plugins without that helping at all.

Normal posts and pages with the standard template load fine, just not pages with page templates that worked 24 hours ago with no changes up to this point in time.

Where would I begin to solve this?

I am using HTML5 Blank to make my site. I wanted to style some pages differently than others, and therefore made a page template for them. In this page template I have used this to get the content:

<?php the_content(); ?>

This worked perfectly yesterday. Then I woke up today and now the same pages show this error and no content:

Warning: count(): Parameter must be an array or an object that implements Countable in /home/insitvbt/treningsglad/wp-includes/post-template.php on line 317

Everything else in the page template file loads fine, just not the content. I can't see anything in the logs about any updates happening from yesterday until today, so this perplexes me a bit.

These are the lines around 317 in post-template.php:

// If the requested page doesn't exist.
Line 317 ---> if ( $elements['page'] > count( $elements['pages'] ) ) {
    // Give them the highest numbered page that DOES exist.
    $elements['page'] = count( $elements['pages'] );
}

I have Googled for about an hour and find many people with the same type of problem, but no apparent solution to my exact case. I have disabled all plugins without that helping at all.

Normal posts and pages with the standard template load fine, just not pages with page templates that worked 24 hours ago with no changes up to this point in time.

Where would I begin to solve this?

Share Improve this question edited Apr 22, 2020 at 7:37 TASan asked Apr 22, 2020 at 7:10 TASanTASan 421 silver badge9 bronze badges 3
  • This isn't also you, is it? wordpress.stackexchange.com/questions/364718/… Are you using pagination in that template? If so, what code are you using for it? – Jacob Peattie Commented Apr 22, 2020 at 7:48
  • Also, are you using the_content() inside the loop? Might be just easier if you can share the full page template code. – Jacob Peattie Commented Apr 22, 2020 at 7:50
  • That is not me, no. You are correct on the loop. All the loop related code had been removed by a mistake. I found it just before seeing your comment. I am posting an answer here now. Thanks! – TASan Commented Apr 22, 2020 at 8:02
Add a comment  | 

1 Answer 1

Reset to default 1

The problem was that the loop related code had been removed from the template file by a mistake without me knowing. I had to add this back in:

<?php if (have_posts()): while (have_posts()) : the_post(); ?>

and

<?php else: ?>

        <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>

<?php endif; ?>

本文标签: errorsPHPwarning in posttemplatephp and no loading content on pages