Sunday, 29 November 2015

How to Create Custom Post Types in WordPress

Use this plugin to create custom post type : https://wordpress.org/plugins/custom-post-type-ui/ Code 1:This is an example
<!--php $args = array('post_type' =--> 'bios','posts_per_page'=>'3' ); //The loop //The display ?>
Code 2: Replace "movies" to your own custom post type name.Which you created
<!--php $args = array( 'post_type' =--> 'movies', 'posts_per_page' => 10 ); $the_query = new WP_Query( $args ); ?> <!--php if ( $the_query--->have_posts() ) : ?> <!--php while ( $the_query--->have_posts() ) : $the_query->the_post(); ?> <h2><!--php the_title(); ?--></h2> <div class="entry-content"> <!--php the_content(); ?--> </div> <!--php wp_reset_postdata(); ?--> <!--php else: ?--> <p><!--php _e( 'Sorry, no posts matched your criteria.' ); ?--></p> <!--php endif; ?-->
Code 3: By default, WordPress will retrieve and display the most recently published content first if you don’t specify any ordering parameters. You can specify this argument to your query to tell WordPress how to sort the items to be displayed. For example, below is the argument to display 3 posts per page and sort the titles in descending order.
<!--php $args = array('post_type' =--> 'bios','posts_per_page'=>'3','order'=>'DESC','orderby' => 'title'); //The loop //The display ?>
Default Example : Perfect Working
<!--php $mypost = array( 'post_type' =--> 'tech_competences', ); $loop = new WP_Query( $mypost ); ?> <!--php while ( $loop--->have_posts() ) : $loop->the_post();?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <!--php if ( has_post_thumbnail() && ! post_password_required() ) : ?--> <div class="entry-thumbnail"> <!--php the_post_thumbnail(); ?--> </div> <!--php endif; ?--> <h1 class="entry-title"><!--php the_title(); ?--></h1> </header><!-- .entry-header --> <div class="entry-content"> <!--php the_content(); ?--> <!--php wp_link_pages( array( 'before' =--> '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?> </div><!-- .entry-content --> <footer class="entry-meta"> <!--php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link"-->', '</span>' ); ?> </footer><!-- .entry-meta --> </article><!-- #post --> <!--php endwhile; ?-->

Share

& Comment

3 comments:

  1. Thanks for sharing this guide, Integrating WordPress Loop is very important to show posts on theme.

    ReplyDelete
  2. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. wordpress website

    ReplyDelete
  3. Thank you very much for writing such an interesting article on this topic. This has really made me think and I hope to read more. WordPress builders

    ReplyDelete

 

Copyright © Taha Codes™ is a registered trademark.