WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#40079 new defect (bug)

Content of static pages does not show when you have a count_post in the theme

Reported by: devlink1337 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Posts, Post Types Keywords:
Focuses: template Cc:
PR Number:

Description

in page.php when you have elsewhere:

<?php
$count_posts = wp_count_posts();
$posts = $count_posts->publish;
$numberofcats = wp_count_terms('category');
echo "<p><u>".$posts." articles in ".$numberofcats. " categories:</u></p>"; 
?>

then the content inside the loop of a static page will display the content of an article. well for me i fixed it with:

<?php $count_posts = wp_count_posts();
$numberofcats = wp_count_terms('category');
echo "<p><u>".$count_posts->publish." articles in ".$numberofcats. " categories:</u></p>"; 
?>

I am testing it on a custom theme but with plain code you will see this too.

tested it on a plain installation with custom theme in page.php:

<?php get_header(); ?>
 	<h2>Categories:</h2>
			<?php $count_posts = wp_count_posts();
			$posts = $count_posts->publish;
			$numberofcats = wp_count_terms('category');
			echo "<p><u>".$posts." articles in ".$numberofcats. " categories:</u></p>"; 
			?>

      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
         <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
         <div class="entry">
            <?php the_content(); ?>
         </div>
      <?php endwhile; endif; ?>

      <?php get_sidebar(); ?>
 
<?php get_footer(); ?>

Change History (1)

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Posts, Post Types
Note: See TracTickets for help on using tickets.