Forums

Join
bbPress Support ForumsThemeslatest wordpress stories (code)

Info

latest wordpress stories (code)

  1. Just made a query in my forum functions.php to display the 5 latest stories from WordPress. Pretty basic but it may help someone:

    // get WP news
    function wpnews() {
    	global $bbdb;
    $stories = $bbdb->get_results("SELECT post_title, guid, post_date_gmt FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date_gmt DESC LIMIT 0,4");
    	foreach ($stories as $story) {
    		if ($i <= 4) {
    		echo '<li><a href="' . $story->guid . '">' .$story->post_title . '</a></li>';
    		$i++;
    		}
    	}
    }

    then call it on your forum with <?php wpnews() ?> and style to suit.

  2. FYI, this only lists 4 posts but is FREAKIN AWESOME! :D

  3. FYI, the if ($i <= 4) { is not needed because you already do a LIMIT on the query.

    Related topic:
    http://bbpress.org/forums/topic/heres-how-to-show-bbpress-info-inside-wordpress-without-full-integration

  4. On my version I'm fetching 10 latest rows, randomizing, then displaying 5 stories.
    $bbdb->get_results("SELECT post_title, guid FROM site_posts WHERE post_type='post' AND post_status='publish' ORDER BY rand() LIMIT 0,10");

    Admittedly, I didn't make the correct alterations to the previous example. Anyway, it should give people an idea of what to do.

    oh, and _ck_ I hadn't spotted your earlier post - it would have made it a lot easier for me to figure out if I had!

  5. and my final correction on the random thing!

    $stories = $bbdb->get_results("SELECT post_title, guid FROM site_posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date_gmt DESC LIMIT 0,10");
    shuffle($stories);

    previous example was getting a random 10 from all posts.
    This get's 10 latest posts, then randomizes them with the 'shuffle'.
    cheers!

  6. Yup "order by rand()" is very handy.
    I used it for a mod for WordPress years ago to make a "random" category which is very useful.
    It could even be done to make a "random topics" view in bbPress but not sure how useful that would be.

    It's fine for casual use but keep in mind for larger tasks it's very slow and makes mysql purists shudder.

  7. You must log in to post.