• Need some help here, folks. I’m not PHP guy, and am trying to implement a more complex WordPress setup than what I’ve done before.

    My goal is a Loop where posts from certain categories are formatted differently (not just style, but actual code, so applying different classes won’t work here). These categories would be 5, 6, and 7. I have a category 8 which is the featured posts that always piggybacks along with category 1 (general purpose blog posts). This will come into play here in a minute.

    I have the following set up as my index.php:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    
    <!-- Start the Loop -->
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
        <!-- Start Category Filter -->
        <!-- Cat 5 THOUGHTS -->
        <?php if ( in_category('5') ) { ?>
    
            Lorem Ipsum
    
        <!-- Cat 6 LINKS -->
        <?php } elseif ( in_category('6') ) { ?>
    
            Lorem Ipsum
    
        <!-- Cat 7 VIDEO -->
        <?php } elseif ( in_category('7') ) { ?>
    
            Lorem Ipsum
    
        <!-- Normal BLOG Format    -->
        <?php } else { ?>
    
            Lorem Ipsum
    
        <!-- End Category Filter -->
        <?php } ?>
    
    <!-- 404 Catch -->
    <?php endwhile; else: ?>
    
        Lorem Ipsum
    
    <!-- Stop the Loop -->
    <?php endif; ?>
    
    <?php get_footer(); ?>

    My most recent posts are a category 5 followed by all category 1’s. There is a single category 8, but it is several posts back.

    However, when I preview this theme to check my work, the Loop does not display as I’ve intended. Instead of several posts with the category 5 formatted differently, only the single category 8 post is shown and nothing else (but hey, at least is is formatted right!).

    Can anyone spot what I’ve done wrong here?

Viewing 1 replies (of 1 total)
  • Thread Starter WillPhillips

    (@theimperial)

    Update: Still unsure as to what is going on, but am certain this is tied into the Featured (8) category.

    My chief finding thus far is that the Loop displays only the first post that has the Feature category (or has the Feature category along with another). It isn’t a multiple category problem, as a post with any two other categories (e.g. Blog & Link) won’t be displayed.

    However, when I set an elseif(in_category(‘Feature’)){} specifically for the Feature category, it seems to ignore it and goes back to the default format of the else{} and still only displays that single post.

    What am I missing here?

    Have I inadvertently bungled my PHP (I’m a hack at best) or is there a WordPress feature/bug I’m missing?

Viewing 1 replies (of 1 total)

The topic ‘Category Based Post Formats in the Loop?’ is closed to new replies.