Aug 31

Displaying Custom Post Types on Home Page



By default, WordPress only displays the loop of contents from the blog post type. If we add custom post types, it doesn’t get automatically displayed on home page. To do so, we have to manually add the php snippet below to the Home page. To explain it simply, we’re adding a new loop to display the custom post type.

In this example, we will add a custom post type called “movie” to our second loop.

<?php query_posts( 'post_type=movie&posts_per_page=3'); ?>
	<?php if (have_posts()) : ?><table><tr>
		<?php while (have_posts()) : the_post(); ?>
<h4><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4><br />
<?php the_excerpt(); ?>
		<?php endwhile; ?>
	<?php endif; ?>

The code above lets you display the 3 most recent posts you have under a custom post type called ‘movie’. Easy stuff eh?

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Related posts:

  1. Create Custom Post Types and Taxonomies on WordPress Hello friends! You don’t know but I’m working on a...
  2. How To Create an Artist Database on WordPress Ever thought of creating something like IMDB or STLyrics or Yahoo...
  3. Displaying Post Thumbnail on WordPress Home Page Here’s how to show post thumbnails on the home page...

1
comments

1 comment!

  1. Ian says:

    Thanks for your great tips. It’s so simple but really help me to show my custom post type list in home page.

Reply

CommentLuv badge

Notify me of followup comments via e-mail. You can also subscribe without commenting.