Each web page in my weblog begins with an embody file. When itemizing “all posts” this header will seem many instances on the web page. To keep away from this I simply launched a world variable that’s initiated on web page load (“parse_query”) and incremented by every web page. I can then learn it and show the header as wanted. It’s not a superb methodology, however I’m solely moderatly skilled with WordPress and knew nothing after I began the weblog 5 yrs in the past and did this.
Now I want to improve to PHP 8.0 and international variables appear to be eliminated as utilized in WordPress ($GLOBALS[‘my_array’][‘1’]). So I have to do away with this international.
How can I obtain a counter inside every submit for what number of posts have already been displayed on the present web page, when itemizing “all posts”?
In Twentytwenty theme, I suppose this loop in file singular.php is the one I want to rely and ship the worth to every web page
if ( have_posts() ) {
whereas ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content material', get_post_type() );
}
}