logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Multiple Loops Query

So, I am in a bind and in the last moments of finishing a theme. However, I thought I would ask someone if they can whip up a multiple loop for the front page that was a last minute request by my client.

I do not need anything but the PHP, but please be decent enough to label what is happening in the multiple loop

What I need is

1. Most recent post and 2 more would be an excerpt with 150 length with a thumbnail (please note I already know how to integrate my own,so just put a hidden code piece with thumbnailcodehere as a placer.
2. The next 5 would be just be Title, thumbnail, and the read more link... no excerpt.

------------

Nile Flores | 10/30/11 at 10:49pm Edit


(3) Possible Answers Submitted...

Note: Nile Flores felt their question was unanswered, so we granted them a refund.

Note: Nile Flores requested a refund. They offered this explanation:

"None of these answer nor work for what I needed. I almost feel like my questions was not even read."

If no one challenges a refund request, then they are automatically granted and proccessed after 48 hours. Admins of this site only review refund requests if someone challenges the request. If you are curious about how we handled previous refund requests, you may read over all refund requests and their challenges.

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    10/30/11
    11:50pm
    Linda says:

    Hi, try something like this...


    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "1") { break; } else { ?>

    <?php the_title(); ?>
    <?php the_content(); ?> // display the full content of the first post only

    <?php $count1++; } ?>
    <?php endforeach; ?>


    <?php query_posts('showposts=2'); ?>
    <?php $posts = get_posts('numberposts=2&offset=1'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "2") { break; } else { ?>

    <?php the_title(); ?> <?php the_excerpt(); ?> // display the excerpt of the next two
    <?php $count2++; } ?>

    <?php endforeach; ?>


    <?php query_posts('showposts=8'); ?>
    <?php $posts = get_posts('numberposts=8&offset=3'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count3 = 0; if ($count3 == "8") { break; } else { ?>

    <a class="" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> // display the last as just title and link

    <?php $count3++; } ?>

    <?php endforeach; ?>


    <?php endwhile; ?>

    <?php else : ?>

    <?php endif; ?>



    You might also want to increase your bid for more answers. :)

    Cheers!

    • 10/31/11 5:47am

      Nile Flores says:

      This seems to spit out unnecessary code and is not what I was asking for.

  • avatar
    Last edited:
    10/30/11
    11:58pm
    Kannan C says:

    <?php

    // The Query for first 3 recent posts
    $the_query = new WP_Query( array( 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '3' ) );

    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<div>'.the_title();
    echo get_the_post_thumbnail('thumbnail', array('class' => 'alignleft') );
    echo the_excerpt_max_charlength(150);
    echo '</div>';
    endwhile;

    // Reset Post Data
    wp_reset_postdata();
    ?>

    The next five recent posts
    <?php

    // The Query for 4 to 9 recent posts
    $the_query = new WP_Query( array( 'post_type' => 'post','orderby' => 'date', 'order' => 'DESC', 'offset=3', 'posts_per_page' => '5' ) );

    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<div>'.the_title();
    echo get_the_post_thumbnail('thumbnail', array('class' => 'alignleft') );
    echo '<a href="'.get_permalink().'">Read more</a>';
    echo '</div>';
    endwhile;

    // Reset Post Data
    wp_reset_postdata();
    ?>


    The following lines to be go on your functions.php file


    add_theme_support( 'thumbnail' ); //to support featured thumbnail

    function the_excerpt_max_charlength($charlength) {
    $excerpt = get_the_excerpt();
    $charlength++;
    if(strlen($excerpt)>$charlength) {
    $subex = substr($excerpt,0,$charlength-5);
    $exwords = explode(" ",$subex);
    $excut = -(strlen($exwords[count($exwords)-1]));
    if($excut<0) {
    echo substr($subex,0,$excut);
    } else {
    echo $subex;
    }
    echo "[...]";
    } else {
    echo $excerpt;
    }
    }

  • avatar
    Last edited:
    10/31/11
    12:16am
    ej_emman says:

    Hello Nile,
    Maybe you can try this...


    //Place this into your function.php,. this will filter the excerpt length

    function new_excerpt_length($length) {
    return 150;
    }
    add_filter('excerpt_length', 'new_excerpt_length');




    //multi loops start here. this will query on the condition given base on what you need.
    // it works on me. hope this helps..

    <?php
    $multi_loops = new WP_Query();
    $multi_loops->query('showposts=7');
    $i = 0;
    ?>

    <?php while ($multi_loops->have_posts()) : $multi_loops->the_post(); ?>
    <li>
    <?php if($i > 2): ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php if(has_post_thumbnail)
    echo the_post_thumbnail(); ?>
    <a href="<?php the_permalink() ?>"> read more...</a>
    <?php else:
    if(has_post_thumbnail)
    echo the_post_thumbnail();
    the_excerpt();
    endif;
    $i++;
    ?>
    </li>
    <?php endwhile; ?>

This question has expired.





Current status of this question: Refunded



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.