WordPress.org

Support

Support » How-To and Troubleshooting » sorting $post?

sorting $post?

  • 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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>

    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

    okay – I forgot about that, sorry forum

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘sorting $post?’ is closed to new replies.
Skip to toolbar