WordPress.org

Ready to get started?Download WordPress

Forums

Page display multiple subcat titles + 2 or 1 posts not working (1 post)

  1. Joskhuu
    Member
    Posted 9 months ago #

    I'm pretty new to wordpress (formally Joomla coder) and i'm struggeling with the loop. I want to display a page that contains subcat's from a category, but also show 2 or 1 post(s) from that subcat.

    Example:
    Page
    - Subcat title
    - Post
    - Post
    - different subcat title
    - Post
    - different subcat title
    - Post
    - Post
    etc.

    In Joomla this is peanuts! But i can't get it to work in WordPress. This is my code so far ... It almost works, the only thing not working is grouping 2 or 1 articles and showing 1 subcat title ;

    <?php query_posts('cat=1 &showposts=999');  ?>
                    <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>
    
                        <div id="project<?php the_field('tekst'); ?>">
    
                            <h2><?php foreach((get_the_category()) as $category) { echo ( $category->cat_name != 'Local' ) ? $category->cat_name . ' ' : ''; } ?></h2>
    
                            <?php the_content(); ?>
    
                        </div>
    
                    <?php endwhile; ?>
                    <?php endif; ?>
                    <?php wp_reset_query(); ?>

    Can someone please help me ?

Reply

You must log in to post.

About this Topic