0

I'm sorry if this question is explained somewhere, I couldn't find it. But it's also difficult to express this special thing in a second language..

I have a very simple homepage, and on that homepage I would like to display a "Tip". I've tried the Daily Tip plugin, as that does seem to do what I would like, but it's very buggy. So I thought, maybe I can single out a category and use posts to show that tip. The homepage is already with just 2 last posts: One from category Blog and one from category Column. On the right side I would like Tip, but with a special styling, so I have to separate it from the normal while loop.

So this would be the result:

article: BLOGPOST - article: COLUMN - custom: DAILY TIP (highlighted)

(I'm not allowed to post an image)

Does anyone have an idea how to achieve this?

Maybe good to know that the code I've entered for the first two posts is:


    $post_ids = array(0);
        foreach( array( 3, 4) as $cat_id ) {
          if ( $posts = get_posts(array('cat' => $cat_id, 'showposts' => 1)) ) {
                $first = array_shift($posts);
            $post_ids[] = $first->ID;
         }
    }
  query_posts(array('post__in' => $post_ids));
 if (have_posts()) : while (have_posts()) : the_post(); >

(and so on)

Thank you so much in advance!

6
  • 1
    What part of this are you having trouble with? I'd use a Custom Post Type for this but what you are doing should work (didn't test it but it looks right except that you should not be using query_posts() pretty much ever).
    – s_ha_dum
    Aug 11, 2013 at 17:09
  • Thank you for your reply. The array works fine, and gives me the first two categories. But the third I would like to always have on the right side, in one position. And with a border to highlight it. So this array could also give me the third category, but then I wouldn't be able to have it stand out, it would be part of the same markup. Why should I not use query_posts()? How would you use the Custom post type? Can you point me into a direction? Can I select custom post types to highlight on the homepage? (It's too bad I can't post images)
    – Rosely
    Aug 11, 2013 at 18:28
  • For query_posts see: The Codex itself also has a warning about query_posts. You are just asking about generating the markup for the results. Do you have any of that code to post?
    – s_ha_dum
    Aug 11, 2013 at 18:35
  • Post a bare URL is you can't post an image. Others here, myself included, can convert it to an inline image.
    – s_ha_dum
    Aug 11, 2013 at 18:36
  • The Custom Post type seems to be what I would like indeed. The only problem remains to call it into the homepage, outside the first 'while loop'. I've found that it must be possible to create a second loop, so I'm going to dive into that tonight. Thanks for the Custom Post Type suggestion :)
    – Rosely
    Aug 12, 2013 at 7:36

1 Answer 1

1

You can place another loop on the template, for example below the first loop.
Multiple loops documentation: http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1

<?php if (have_posts()) : ?>
           <?php while (have_posts()) : the_post(); ?>    
           <!-- your first loop ... -->
           <?php endwhile; ?>
 <?php endif; ?>

<?php
wp_reset_query();

$tips_query = new WP_Query( 'category_name=tips&posts_per_page=1' );
?>

<?php if ($tips_query->have_posts()) : ?>
           <?php while ($tips_query->have_posts()) : $tips_query->the_post(); ?>    
           <!-- do stuff ... -->
           <?php endwhile; ?>
 <?php endif; ?>

<?php wp_reset_postdata(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.