Honesty Rocks! truth rules.

Wordpress Showing Designated Posts

HOME      >>       Websites and Web Designing

Little Asterisk

Hello everyone,

As I am a sort-of beginner with Wordpress (well, actually - I understand the basics, but am never sure if there is an easier way to do something), I'd like to ask a question for someone more experienced than me.

The problem is; I want to show one post from category X on the front page, one from category Y, one from category Z and so forth (well, actually only 4-5 categories).

Now, I have a way to do that, but am wandering if there is some easier way to accomplish the same using, perhaps an easier technique. Here's what I have so far:

<?php $news = new WP_Query('category_name=News&posts_per_page=1'); ?> <?php while ($news->have_posts()) : $news->the_post(); ?> <div > <h1 ><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h1> </div> <?php endwhile; ?> <?php $articles = new WP_Query('category_name=Articles&posts_per_page=1'); ?> <?php while ($articles->have_posts()) : $articles->the_post(); ?> <div > <h1 ><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h1> </div> <?php endwhile; ?><!-- etcetera -->


Now, as you can see, the principle is the same as can be seen on https://codex.wordpress.org/The_Loop%23Multiple_Loops_Example_1 (the middle example, where it says <!-- do special_cat stuff... -->).

Since repeating that might be too hard on the bandwidth and PC, I believe there is an easier way of achieving this. And I hope I'm right :)

(And if I'm not; well, you can probably see that I'm a beginner with Wordpress :))

Thanks for your help!