List Post Titles For Current Category

7 replies
I'm creating a template and seem to be stuck while I'm creating my category template. Currently I have all my posts listed when you click on a category. I'm wanting to include a list of post titles at the top for quick navigation. What would be the correct loop for this? Or do I need to create individual templates for each category and go the query_posts( 'cat=3' ); and echo out the_title(); route?
#category #current #list #post #titles
  • Profile picture of the author ussher
    real hard to understand your question.

    is this php?
    is this wordpress?
    something else?
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5306884].message }}
    • Profile picture of the author drewhowell21
      Originally Posted by ussher View Post

      real hard to understand your question.

      is this php?
      is this wordpress?
      something else?
      Sorry about that. I've been staring at Notepad++ too long.

      I'm working on creating a Wordpress Template. I'm in the process of creating a category page template. Currently, I have the category page displaying all post content for all posts (title, thumbnail, excerpt, etc). I'm wanting to create a list of only post titles ( the_title(); ) for the current category page. I've only found solutions where you have to query categories by id to echo out posts. I'm looking for a solution that goes off the current category.
      {{ DiscussionBoard.errors[5306923].message }}
      • Profile picture of the author SteveJohnson
        Originally Posted by drewhowell21 View Post

        Sorry about that. I've been staring at Notepad++ too long.

        I'm working on creating a Wordpress Template. I'm in the process of creating a category page template. Currently, I have the category page displaying all post content for all posts (title, thumbnail, excerpt, etc). I'm wanting to create a list of only post titles ( the_title(); ) for the current category page. I've only found solutions where you have to query categories by id to echo out posts. I'm looking for a solution that goes off the current category.
        If I understand you correctly, you just want an extra list of the post titles that appear later on the page?

        If that's right, it's terribly easy - you have the array of post objects available anywhere within the template, so you can just use multiple loops by hitting the rewind button (this code has no HTML, you'll have to add in what you need):
        Code:
        <?php
        ## first loop, for titles
        if ( have_posts() ): while ( have_posts() ) : the_post();
        the_title();
        endwhile; endif;
        ## 'rewind' to make the loop available again
        rewind_posts();
        
        ## do other template stuff here
        
        ## now, another loop
        if ( have_posts() ): while ( have_posts() ) : the_post();
        the_permalink(); the_content();
        endwhile; endif;
        ?>
        Signature

        The 2nd Amendment, 1789 - The Original Homeland Security.

        Gun control means never having to say, "I missed you."

        {{ DiscussionBoard.errors[5309583].message }}
        • Profile picture of the author drewhowell21
          Originally Posted by SteveJohnson View Post

          If I understand you correctly, you just want an extra list of the post titles that appear later on the page?

          If that's right, it's terribly easy - you have the array of post objects available anywhere within the template, so you can just use multiple loops by hitting the rewind button (this code has no HTML, you'll have to add in what you need):
          Code:
          <?php
          ## first loop, for titles
          if ( have_posts() ): while ( have_posts() ) : the_post();
          the_title();
          endwhile; endif;
          ## 'rewind' to make the loop available again
          rewind_posts();
          
          ## do other template stuff here
          
          ## now, another loop
          if ( have_posts() ): while ( have_posts() ) : the_post();
          the_permalink(); the_content();
          endwhile; endif;
          ?>
          I'm pretty sure this is what I need. The part I'm still not understanding is how to only list posts from the current category page I'm on. I know I can target individual categories by their id, but that would involve creating separate templates for each category. Am I overlooking something that's extremely obvious? I'm currently at work, so I'm not able to "play" around with it at the moment.
          {{ DiscussionBoard.errors[5309922].message }}
          • Profile picture of the author drewhowell21
            I was able to get my categories listed by running a second loop. Thanks a lot, man!

            PHP Code:
            <div class="postlist">
                            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                                
                                    <ul>
                                        <li class="posttable"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a>    </li>    
                                    </ul>    
                                    
                            <?php endwhile; else: ?>
                            <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
                            <?php endif; ?>
            </div>
            How could I get that to display in multiple columns? "column-count:3;" doesn't seem to work.
            {{ DiscussionBoard.errors[5310866].message }}
  • Profile picture of the author ussher
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5307016].message }}
  • Profile picture of the author shantanu
    This is basically a PHP code guys.....coz if wordpress will give these types of errors then it must be in SQL Server form.
    {{ DiscussionBoard.errors[5310858].message }}

Trending Topics