$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - Only one post is showing on category page, why?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - Only one post is showing on category page, why?

matteradmin6PV0评论

My website categories are only showing one recent post, not all.

category.php code looks like this:

<?php
get_header(); 
/**
 * The template for displaying Category pages
 */
quality_breadcrumbs();
?>

<section id="section-block" class="site-content">
    <div class="container">
        <div class="row">
        <!--Blog Posts-->
        <?php echo '<div class="col-md-'.( !is_active_sidebar( "sidebar-primary" ) ?"12" :"8" ).' col-xs-12">'; ?>
            <article class="cat-post">  
            <figure class="cat-figure">
        <?php $defalt_arg =array('class' => "img-responsive"); ?>
            <?php if(has_post_thumbnail()): ?>
            <a  href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail($defalt_arg); ?>
            </a>
            <?php endif; ?> 

        </figure>
        <div>

            <?php if($current_options['home_meta_section_settings'] == '' ) {?>

<?php } ?>

            <header class="entry-header">
                <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            </header>   
            <div class="entry-content">
                <?php the_excerpt(__('Read More','quality')); ?>

            <?php if($current_options['home_meta_section_settings'] == '' ) {?>     

            <span class="entry-meta">
                <?php $cat_list = get_the_category_list();
                if(!empty($cat_list)) { ?>

            <span class="author-image"> <?php echo ' ';?><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) );?>"><?php echo get_the_author();?></a> |</span><span class="cat-links"><?php _e('','quality');?><a href="<?php the_permalink(); ?>"><?php the_category(' '); ?></a></span> |  <a class="entry-date" href="<?php echo get_month_link(get_post_time('Y'),get_post_time('m')); ?>"> <?php echo get_the_date('M j, Y'); ?></a>
                <?php } ?>
                </span>
            </div>
            <?php } ?>
        </div>
</article>              
        <?php wp_link_pages();?>    
        <!--/Blog Content-->
        <?php comments_template('',true); ?>
        </div>
        <?php get_sidebar(); ?>
    </div>
</section>
<?php get_footer(); ?>

Please check and let me know.

My website categories are only showing one recent post, not all.

category.php code looks like this:

<?php
get_header(); 
/**
 * The template for displaying Category pages
 */
quality_breadcrumbs();
?>

<section id="section-block" class="site-content">
    <div class="container">
        <div class="row">
        <!--Blog Posts-->
        <?php echo '<div class="col-md-'.( !is_active_sidebar( "sidebar-primary" ) ?"12" :"8" ).' col-xs-12">'; ?>
            <article class="cat-post">  
            <figure class="cat-figure">
        <?php $defalt_arg =array('class' => "img-responsive"); ?>
            <?php if(has_post_thumbnail()): ?>
            <a  href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail($defalt_arg); ?>
            </a>
            <?php endif; ?> 

        </figure>
        <div>

            <?php if($current_options['home_meta_section_settings'] == '' ) {?>

<?php } ?>

            <header class="entry-header">
                <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            </header>   
            <div class="entry-content">
                <?php the_excerpt(__('Read More','quality')); ?>

            <?php if($current_options['home_meta_section_settings'] == '' ) {?>     

            <span class="entry-meta">
                <?php $cat_list = get_the_category_list();
                if(!empty($cat_list)) { ?>

            <span class="author-image"> <?php echo ' ';?><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) );?>"><?php echo get_the_author();?></a> |</span><span class="cat-links"><?php _e('','quality');?><a href="<?php the_permalink(); ?>"><?php the_category(' '); ?></a></span> |  <a class="entry-date" href="<?php echo get_month_link(get_post_time('Y'),get_post_time('m')); ?>"> <?php echo get_the_date('M j, Y'); ?></a>
                <?php } ?>
                </span>
            </div>
            <?php } ?>
        </div>
</article>              
        <?php wp_link_pages();?>    
        <!--/Blog Content-->
        <?php comments_template('',true); ?>
        </div>
        <?php get_sidebar(); ?>
    </div>
</section>
<?php get_footer(); ?>

Please check and let me know.

Share Improve this question edited Nov 27, 2018 at 9:01 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 27, 2018 at 8:47 rudyardsrudyards 233 bronze badges 2
  • Please post your code here and not using some external sites... – Krzysiek Dróżdż Commented Nov 27, 2018 at 9:00
  • developer.wordpress/themes/basics/the-loop – Jacob Peattie Commented Nov 27, 2018 at 9:42
Add a comment  | 

1 Answer 1

Reset to default 0

It's pretty easy to see why your code shows only one post - there is no loop in your template file, so why should it show more posts than one?

To be honest... It looks more like single post template and not like category archive...

This should work a little bit better (or at least it should show more posts):

<?php
get_header(); 
/**
 * The template for displaying Category pages
 */
quality_breadcrumbs();
?>

<section id="section-block" class="site-content">
    <div class="container">
        <div class="row">
        <!--Blog Posts-->
        <?php echo '<div class="col-md-'.( !is_active_sidebar( "sidebar-primary" ) ?"12" :"8" ).' col-xs-12">'; ?>
            <?php while ( have_posts() ) : the_post(); ?>
            <article class="cat-post">  
                <figure class="cat-figure">
                    <?php $defalt_arg =array('class' => "img-responsive"); ?>
                    <?php if(has_post_thumbnail()): ?>
                    <a  href="<?php the_permalink(); ?>">
                        <?php the_post_thumbnail($defalt_arg); ?>
                    </a>
                    <?php endif; ?> 
                </figure>

                <div>    
                    <?php if($current_options['home_meta_section_settings'] == '' ) {?>

                    <?php } ?>

                    <header class="entry-header">
                        <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    </header>   

                    <div class="entry-content">
                        <?php the_excerpt(__('Read More','quality')); ?>

                        <?php if($current_options['home_meta_section_settings'] == '' ) { ?>     

                        <span class="entry-meta">
                            <?php $cat_list = get_the_category_list();
                                if(!empty($cat_list)) {
                            ?>

                            <span class="author-image"> <?php echo ' ';?><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) );?>"><?php echo get_the_author();?></a> |</span><span class="cat-links"><?php _e('','quality');?><a href="<?php the_permalink(); ?>"><?php the_category(' '); ?></a></span> |  <a class="entry-date" href="<?php echo get_month_link(get_post_time('Y'),get_post_time('m')); ?>"> <?php echo get_the_date('M j, Y'); ?></a>
                            <?php } ?>
                        </span>
                    <?php } ?>
                </div>
            </article>    
            <?php endwhile; ?>          

            <?php wp_link_pages();?>    
            <!--/Blog Content-->
            <?php comments_template('',true); ?>
        </div>
        <?php get_sidebar(); ?>
    </div>
</section>
<?php get_footer(); ?>
Post a comment

comment list (0)

  1. No comments so far