WordPress.org

Ready to get started?Download WordPress

Forums

Display categories followed by their posts (1 post)

  1. helpmeplease90
    Member
    Posted 6 months ago #

    How could I possibly display a list of category titles and their posts below them on the index.php.

    Every section DIV should be a category, with a LI list of every post.

    <?php get_header(); ?>
    <!-- START CATEGORY -->
    <div class="section">
    <!-- CATEGORY TITLE -->
    <h2><?php
    $category = get_the_category();
    echo $category[0]->cat_name;
    ?></h2>

      <?php while ( have_posts() ) : the_post() ?>
      <!-- START LIST OF POSTS IN THE CATEGORY -->

    • <div class="header">
      <div class="checkbox">
      <input class="checkj" type="checkbox" id="c<?php the_ID(); ?>" name="cc" />
      <label for="c<?php the_ID(); ?>"><span></span></label>
      </div>
      <h4><?php the_title(); ?><?php
      $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' =>'any', 'post_parent' => $post->ID );
      $attachments = get_posts( $args );
      if ( $attachments ) {
      foreach ( $attachments as $attachment ) {
      the_attachment_link( $attachment->ID , false );
      echo '<span>' . $attachment->post_date . '</span>';
      }
      }
      ?></h4>
      </div>
      <?php the_content(); ?>
    • <?php endwhile; ?>

    </div>
    </div>
    <?php get_footer(); ?>

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 6 months ago by helpmeplease90
  • This topic is not resolved
  • WordPress version: 3.9.2