Jump to content
xisto Community
Little Asterisk

Wordpress Showing Designated Posts

Recommended Posts

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 class="news">                <h1 class="post-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?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 class="articles">                <h1 class="post-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?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!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.