Custom post-types are incredibly useful when developing custom WordPress environment. In essence, in allows one to generate a specific post-type (i.e. Products or Songs) that can easily be called throughout a WordPress site. For example, one could create a post-type called Products that can be called edited separate from posts and/or pages which can help keep content entry simple and organized.
Lets explore how one would generate a new custom post-type. Traditionally, one would need to edit the functions.php file located in their  theme to generate a custom post-type. However, this method although is a bit outdated. Today, users have a much more user-friendly method to generate post-types using a plugin called Custom Post Type UI which can be downloaded here. The plugin allows for a user to very easily create, edit, and manipulate a custom post-types. Let’s say we have a music blog and want to have a custom post-type for songs…
  1. Download and install Custom Post Type UI through the “Add New” plugin feature in your WordPress admin panel
  2. Click on the Custom Post Type tab generated on the right hand side of the your admin panel after plugin install
  3. Click “Add new”
  4. Fill out the fields – for music example – Post Type Name: songs; Label: Songs; Singular Label: Song; Description: This is where you enter new songs to be featured on your site!
  5. Ignore the options for now unless you are an advanced user
  6. Click on “Create Custom Post Type”
  7. And you’re done!

To call your custom post type simply the below loop in your theme file. Be sure to replace the bold areas with your information.

 

<?php $loop = new WP_Query( array( 'post_type' => 'your_custom_post_name', 'posts_per_page' => 10 ) ); ?> 

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?> 

<?php the_title( '<h2><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?> 

<div> <?php the_content(); ?> </div> 

<?php endwhile; ?>

 

Pin It on Pinterest

Share This