The MU forums have moved to WordPress.org

Recent Images (3 posts)

  1. Doobus
    Member
    Posted 16 years ago #

    The best example I've seen of this so far is vox.com. I know we have recent posts, but is it possible to pull recent photos uploaded as well? Thanks in advance, John.

  2. suleiman
    Member
    Posted 16 years ago #

    is VOX mu-powered? I didn't think they were!

  3. dsader
    Member
    Posted 16 years ago #

    Try post_type as attachment.

    function recent_attachment ($limit, $len, $before_title = '<li>', $after_title = '</li>', $before_post = '', $after_post = '', $show_pass_post = false, $show_excerpt = false) {
        global $wpdb;
    
    $tableposts = $wpdb->posts;    
    
    $sql = "SELECT ID, post_title, post_date, post_content FROM $tableposts WHERE post_type = 'attachment' ";
    	if(!$show_pass_post) $sql .= "AND post_password ='' ";
    	$sql .= "ORDER BY post_date DESC LIMIT $limit";
        $posts = $wpdb->get_results($sql);
    	$output = '';
        foreach ($posts as $post) {
            $post_title = stripslashes($post->post_title);
    		$post_title = str_replace('"', '', $post_title);
            $permalink = get_permalink($post->ID);
    		$post_content = strip_tags($post->post_content);
    		$post_content = stripslashes($post_content);
            $output .= $before_title . '<a href="' . $permalink . '" rel="bookmark" title="Permanent Link: ' . $post_title . '">' . $post_title . '</a>' . $after_title;
    		if($show_excerpt) {
    			$words=split(" ",$post_content);
    			$post_strip = join(" ",array_slice($words,0,$len));
    			$output .= $before_post . $post_strip . $after_post;
    	    }
    
    	}
    	echo $output;
    }

About this Topic