Support » Plugins » Altering a mini loop and PHP

  • I have a static front page, with a sort of mini-loop showing news posts on our site. I want to be able to make a post set with a future post date in the timestamp, which works fine every where else. It doesn’t work in the mini-loop because that takes all posts that have been published (regardless of date).

    Here is the code we’re using…

    # Here starts Mini Loop
    $how_many=8; //How many posts do you want to show

    function niceDate($s) { return strftime("%A %e %B %Y", strtotime($s)); }
    function extrac($s) { return substr(strip_tags($s),0,100); }
    $news=$wpdb->get_results("SELECT DISTINCT $wpdb->posts.ID as ID, $wpdb->posts.post_title AS post_title, $wpdb->posts.post_date AS date, $wpdb->posts.post_content AS text FROM $wpdb->posts LEFT OUTER JOIN $wpdb->post2cat ON $wpdb->posts.ID = $wpdb->post2cat.post_id WHERE $wpdb->posts.post_status = \"publish\" AND NOT ($wpdb->post2cat.category_id = 3 OR $wpdb->post2cat.category_id = 10) ORDER BY ID DESC LIMIT ".$how_many);
    foreach($news as $np){
    printf ("<span class='extract'>%s</span><br/>%s<br/><span class='extract'>%s...</span><br/> <br/>", niceDate($np->date),$np->ID,$np->post_title,extrac($np->text));

    I think what we’ll need to do is take this code WHERE $wpdb->posts.post_status = \”publish\” AND NOT ($wpdb->post2cat.category_id = 3 OR $wpdb->post2cat.category_id = 10) and add another exception to it. However, I’m not familiar enough with PHP to do this myself.

    Is anyone willing to lend their skills to this problem for me?

  • The topic ‘Altering a mini loop and PHP’ is closed to new replies.