0
votes

I am developing my first WordPress site and I am using the Customizr theme. I need to build a front page, that shows the latest posts from 2 categories - News and Events and all their child categories. So my category tree looks like this:

Articles

-News

--First news child category

--Second news child category

-Events

--First events child category

--Second events child category

and I want the front page to show the category News and the category Events with all the posts in their child categories packed in 2 containers with the headlines News and Events respectively. I am a total newbie in WordPress and I've searched for days for a solution, but I think I'm searching with the wrong keywords, because I didn't found what I need. I've created a child theme, and I'm currently trying to make an index.php with The Loop to achieve that. I've also tried making a static front page which uses a different template.

So which is the right way to do that? Can you please at least give me some pointers? Thank you!

1

1 Answers

1
votes

If i understood corectly you can achieve expected result with Category Parameters for WP Query. Then you can loop over posts like this:

<?php 

$the_query = new WP_Query( "category_name=news,events"); ?>

<?php if ( $the_query->have_posts() ) : ?>

    <!-- pagination here -->

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->

    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Also, to customize your front page better make a new template (home.php), do your job there and then asssign it to an empty page and make that page your front page from Settings->Reading