posts, catagories and jquery (2 posts)

  1. bluedrag
    Posted 4 years ago #

    Hi WordPress community,

    I'm trying to display my posts/post categories in a certain way with jquery and I'm just wondering if there is an easy way to do this that I cannot think of.

    Basically I want them displayed like this
    with the section headers being the post categories and the content inside each sections being a list of the posts themselves.
    Don't worry about implimenting the jquery, I'm good at that, what I don't really know how to do is getting all the posts displayed in a list underneath there respective categories.

    Any help is appreciated.

  2. Curtiss Grymala
    Posted 4 years ago #

    You will probably need to run multiple loops in order to do this.

    You would start by retrieving a list of all of the categories. You can use get_all_category_ids to do that.

    Then, you would loop through those and call a query to retrieve all posts in each. That might look something like:

    $cats = get_all_category_ids();
    foreach( $cats as $cat ) {
      query_posts( 'cat=' . $cat );
      if( have_posts() ) :
        // Output the category title
        echo '<h1>' . get_category( $cat )->name . '</h1>';
        // Loop through the posts in this category
        while( have_posts() : the_post();
          // Output the category info here

Topic Closed

This topic has been closed to new replies.

About this Topic