Forums

Show only recent posts and not pages. (4 posts)

  1. BluesplayerMark
    Member
    Posted 3 years ago #

    Hi

    How can this code be altered so that only posts show and not pages.

    <? php cypher_latestposts(); ?>
    
    */
    
    function cypher_latestposts($before='', $after='<br />') {
    
    	global $wpdb;
    	$output = '';
    	$max_posts = 1;	//Maximum posts to be displayed
    
    	$request = "SELECT ID, post_title, post_date FROM $wpdb->posts WHERE post_status ='publish' ";
    	$request .= "ORDER BY post_date DESC LIMIT $max_posts";
    	$posts = $wpdb->get_results($request);
    
    	if($posts){
    
    		foreach ($posts as $post){
    			$post_title = stripslashes($post->post_title);
    			$post_link = stripslashes($post->ID);
    			$post_date = stripslashes($post->post_date);
    
    			//$output .= $before . $post_date . $after;
    			$output .= $before . '<a href="?p=' . $post_link . '" rel="Bookmark" title="Permanent Link to ' . $post_title . '">' . $post_title . '</a>';
    			$output .= $after;
    		}
    	}
    	echo $output;
    }
    ?>

    The author's website is down so I can't ask him.

    Regards
    Bluepslayer

  2. yakuphan
    Member
    Posted 3 years ago #

    $request = "SELECT ID, post_title, post_date FROM $wpdb->posts WHERE post_status ='publish' AND post_type='post' ";

  3. BluesplayerMark
    Member
    Posted 3 years ago #

    Great - works a treat.

    Thanks

  4. tpflanz
    Member
    Posted 2 years ago #

    This post helped answer my question as well. I did not want pages showing in widgets regarding posts

Topic Closed

This topic has been closed to new replies.

About this Topic