PHP – How can I add category to a code with post previews?
-
How can preview thumbnails + titles only from a category?
Right now the code is for showing all posts, but I only want to show posts from a one category.Here is the code from a page template:
<?php $args = array( 'numberposts' => 12 ); $homeposts = get_posts( $args ); foreach($homeposts as $post) : setup_postdata($post); ?> <div class="homepost grid_4"> <?php $thumb = get_post_thumbnail_id(); $img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big) $image = aq_resize( $img_url, 300, 200, true ); //resize & crop the image ?> <?php if($image) : ?> <a href="<?php the_permalink(); ?>"> <img src="<?php echo $image ?>"/></a> <?php endif; ?> <h2> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h2> <div class="home-meta"> <?php _e('Posted on', 'web2feel') ?> <?php the_time('F j - Y'); ?> </div> <?php wpe_excerpt('wpe_excerptlength_index', ''); ?> <a class="readmore" href="<?php the_permalink(); ?>"> Read More </a> </div> <?php endforeach; ?>
- The topic ‘PHP – How can I add category to a code with post previews?’ is closed to new replies.