I’m using a child theme for Stargazer. I wanted to create a page template based on the Stargazer page.php.
So, I copied content/page.php to my theme folder as /mytemplate.php. Other than adding the Template Name: code comment I didn’t change it for now. Assigning it to a page and loading it fails with
Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/post-template.php on line 284
It is caused when <?php the_content(); ?> is evaluated, doh.
You copied the incorrect template for creating a custom page template. Anything under /content is just the “content” area of the page. It’s missing important bits like The Loop and such.
Got it, thank you. The reason I ended up copying page.php is because I simply needed a page without title. How can this be accomplished with minimal modification effort? If I copy index.php I would have to copy everything else as well, no (if I only need to tweak the page template)?
I’m using a child theme for Stargazer. I wanted to create a page template based on the Stargazer
page.php
.So, I copied
content/page.php
to my theme folder as/mytemplate.php
. Other than adding theTemplate Name:
code comment I didn’t change it for now. Assigning it to a page and loading it fails withIt is caused when
<?php the_content(); ?>
is evaluated, doh.There is a long discussion about several aspects / causes for this error at https://core.trac.wordpress.org/ticket/42814 but I don’t see how any of that applies to my case.
I feel I’m missing something obvious.
You copied the incorrect template for creating a custom page template. Anything under
/content
is just the “content” area of the page. It’s missing important bits like The Loop and such.The template you need to copy is
index.php
: https://github.com/justintadlock/stargazer/blob/master/index.phpGot it, thank you. The reason I ended up copying
page.php
is because I simply needed a page without title. How can this be accomplished with minimal modification effort? If I copyindex.php
I would have to copy everything else as well, no (if I only need to tweak the page template)?You’d need to copy
index.php
. Then, replace this line within the file:With this code from
/content/page.php
, which leaves out the header/title code:Thank you so much.