Support » Fixing WordPress » Output posts from category

  • Hello i have this working code for output all posts on front page.

    <?php
    
    get_header(); 
    
    $news_count = 0;
    $limit = 54;
    $page = max(get_query_var('page')-1, 0);
    
    $start_key = $page * $limit;
    $end_key = $page * $limit + $limit - 1;
    
    global $wpdb;
    
    $posts_table = $wpdb->prefix . "posts";
             
    $query = "SELECT $posts_table.ID, $posts_table.post_date, $posts_table.post_title,$posts_table.post_content  FROM $posts_table\n";
    
    $query .= "\tWHERE $posts_table.post_type = 'post'\n";
    $query .= "\tAND $posts_table.post_status = 'publish' ORDER BY post_date DESC ";
    
    $recent_news = $wpdb->get_results( $query );
    
    ?>
    <div class="container">
    <div class="col-xs-12 col-sm-12 col-md-12">
    	     
    	  <?php
            
                $news_count = count($recent_news);
                $news_key = -1;
                $page_count = ceil($news_count / $limit);
                if($page_count > 1)
                {
                            ?>
                            
                     	<?php
    	if (!$page) $page=1;	
        $page_count = ceil($news_count / $limit);
        echo igor_paginator($limit, $page, $news_count, $page_count, "/"); 
    
          ?>	     
                            
                            <?php
                    }
                    
                foreach ($recent_news as $news)
                { 
    		$news_key++;
                    if($start_key > $news_key) continue;
                    if($end_key < $news_key) break;
    
                    ?>
    			 <div style="width: 350px; height:220px; display: inline; float: left; margin:10px; margin-bottom:30px; margin-top:30px;">
    	          
    	          
    	          
    	           <a>" href="<?php echo get_permalink($news->ID ); ?>"><?php echo get_the_post_thumbnail( $news->ID, array(343, 180), array('class' => 'sunnews-thumb', 'alt' => $news->post_title, 'title' => $news->post_title, 'style' => 'width: 343px; height: 180px;') );?></a> 
    	             
    	             <div><b><a>ID ); ?>" style="color:#000; font-size: 18px;"><?php echo $news->post_title;?></a></b>
    	             
    	             
    	             
    	             </div>
    				 
    				</div>
    				
    				
    		<?php    
           
                }
        
        ?>
        <div style="clear: both;"></div>
        		
    	 
    		<?php
    	if (!$page) $page=1;	
        $page_count = ceil($news_count / $limit);
        echo igor_paginator($limit, $page, $news_count, $page_count, "/");
        
    
          ?>		
    
     </div>	  
    
     </div>	
     <div class="container">
    
    <?php get_footer(); ?>
    
    </div>

    How to make it code for output posts from category ? I tried to do this,
    $recent_news = get_the_category($post->ID);
    but this output only one post from category

    • This topic was modified 2 years, 7 months ago by  Steve Stern. Reason: put code in backticks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Output posts from category’ is closed to new replies.