For show featured posts in wordpress on home page. You can select article to show on home page. We have code snippet for show featured posts in wordpress. Showing featured post is good for seo also. Important and selected article you can show on home always. Featured post is great functionality introduced by wordpress.
show featured posts in wordpress
Some times we want to need to show featured posts in wordpress blogs on home page. You can select most popular or nice articles to show on home page. In this tutorial I will will show how you can show the featured wordpress posts on home page.
There is very simple way to show featured post on home page. First you need to create featured wordpress category and whatever post you want to show as featured post that posts select under featured post.
Then use following code:
<?php query_posts('category_name=featured&posts_per_page=5'); if (have_posts()) : while (have_posts()) : the_post(); ?> <?php the_title(); ?> <?php the_excerpt(); ?> <?php endwhile; endif; ?>
Above code you need use in index.php and single.php file. Or you can following code for showing featured wordpress post.
<?php while ( have_posts() ) : the_post() ?> <?php if(get_post_meta($post->ID, 'type', true) == "featured") {; ?> <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"> <img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" /> </a></h2> <?php }; ?> <div class="entry-content"> </div><!– .entry-content –> <?php endwhile; ?>
can i use this code in archive page ?
yes. you can.