I would like to do 3 posts of post_type "daily" and between them a different post_type "quotes"

I would like to do 3 by 3 like for each 3 daily, show a post_type "quotes".

How can I do that?~


here's the code I have so far (PREVIOUS QUERY):

 query_posts( $new_args );
        if (have_posts()) :
            $count = 0;
            while ( have_posts() ) : the_post();
                if ( $count == TRYING_TO_FIGURE_HOW_TO_DO ){
                        $argsQuotes = array(
                                        'post_type'     => 'quotes'
                        $queryQuote = new WP_Query ( $argsQuotes );

                        if ( $queryQuote->have_posts() ) :
                            while ( $queryQuote->have_posts() ) :

                                echo '<li data-url="' . get_permalink() . '"></li>';

                    echo '<li data-url="' . get_permalink() . '"></li>';

I wanna do it 3 by 3 but I can't figure how to do this.

  • Can you show the code you've tried so far? Please show in detail what you want to achieve, to increase the change of others understanding the problem. thanks – birgire Aug 25 '16 at 10:16
  • I have updated with the code I have so far – bugfire Aug 25 '16 at 10:23

There are several ways to do this. Here's an easy one. Let's say you want to mix 9 'daily' posts and 3 'quotes'. First you would have to get those posts:

$dailies = get_posts(array('posts_per_page' => 9, 'post_type' => 'daily'))
$quotes = get_posts(array('posts_per_page' => 3, 'post_type' => 'quote'))

Next you would loop through them like this:

for ($i = 0; $i <= 9; $i++) {
  // html to output $dailies[$i]
  $j = (($i-2)/3) // will be integer if $i=2, 5, 7, so after three dailies
  if (is_int($j) {
    // html to output $quotes[$j]

You will need to add some extra logic to prevent errors in case there are less than 9 or 3 posts respectively.

  • i don't think I explained myself so well. Imagine I have a Post Per Page, like outputing a SINGLE.php with post type_daily. I have a Next Page Button. If i click 3 times in the next it outputs a single.php with post_type 'quotes'. And so On. – bugfire Aug 25 '16 at 10:38
  • That is really quite a different question. It's about navigation: what to show in the Next Page Link. Right? – cjbj Aug 25 '16 at 10:44
  • It's the same, but the query is different if the $count number is, for example 3, or 7 and so on, if its not it shows the dailies query. – bugfire Aug 25 '16 at 10:46
  • Except that you would have to keep track of your indexes not on one page, but between several pages. You could use a query_var for that and use an offset when getting the posts. – cjbj Aug 25 '16 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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