WordPress.org

Ready to get started?Download WordPress

Forums

sorting $post? (4 posts)

  1. AndreSC
    Member
    Posted 8 years ago #

    I built a loop around The Loop to group category listings according to a custom field value, but because each loop needs to run through all the posts, to select and show its relevant posts, I had to disable the limit of how many entries are posted – problem :- (

    Can one (and how) sort the content of the $posts variable (e.g. php?) before calling The Loop, any pointers?

    e.g. http://www.davidkrutpublishing.com/dkp

    thanx

  2. AndreSC
    Member
    Posted 8 years ago #

    e.g. my code is
    <!-- WP Loop starts here -->
    <?php if (have_posts()) : ?>
    <?php // loop through the 3 grouping critera
    $i = 1;
    while ($i <= 3):
    ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php
    $pub=get_post_meta($post->ID, 'Publisher', true);
    $kind="Books";// by default
    $pubkey="";
    if ( in_category(13) ) {
    $pub="David Krut Publishing ";
    $kind="News"; // to allow check to for comments or not later
    }

    if ($i == 1 ) {
    $pubkey="David Krut Publishing ";
    }
    if ($i == 2 ) {
    $pubkey=" Tate ";
    }
    if ($i == 3 ) {
    $pubkey=" Other";
    }
    // print only selected group for this run
    if ($pub==$pubkey){?>
    ...
    <?php if ($kind=="News") {
    the_excerpt();
    echo "<p><a href=\"";
    the_permalink();
    echo "\" rel=\"bookmark\" title=\"Link to";
    the_title();
    echo "\">";
    echo "View this entry in full &raquo</a></p>";
    } else {
    the_content('Read more &raquo;');
    } ?>
    <?php if ($kind=="Books") {
    include (TEMPLATEPATH . '/print-fields.php');// Print custom fields
    include (TEMPLATEPATH . '/order_this.php');
    }
    ?>
    </div>
    ...

  3. spencerp
    Member
    Posted 8 years ago #

    I wouldn't post that though AndreSC, a moderator might delete it for too long of code.. paste it in pastebin.com and give that url..

    spencerp

  4. AndreSC
    Member
    Posted 8 years ago #

    okay - I forgot about that, sorry forum

Topic Closed

This topic has been closed to new replies.

About this Topic