Guest User

Untitled

a guest
Jan 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // Add this code to your functions.php
  2. add_action( 'init', 'create_post_type' );
  3.  
  4. function create_post_type() {
  5. register_post_type( 'products',
  6. array(
  7. 'labels' => array(
  8. 'name' => __( 'Products' ),
  9. 'singular_name' => __( 'Products' )),
  10. 'public' => true,
  11. 'has_archive' => true,
  12. 'rewrite' => array('slug' => 'products')
  13. )
  14. );
  15. }
  16.  
  17. // Add this code in your template file
  18. <?php
  19. /**
  20. * Template Name: Products
  21. * Description: Product template
  22. *
  23. * @package Waipoua
  24. * @since Waipoua 1.0
  25. */
  26.  
  27. get_header(); ?>
  28.  
  29. // The loop for your custom post Types
  30. <ul class="products">
  31. <?php $args = array( 'post_type' => 'products', 'posts_per_page' => 30, 'orderby' => 'rand' );
  32. $loop = new WP_Query( $args );
  33. while ( $loop->have_posts() ) : $loop->the_post();
  34. echo '<li>';
  35. the_title('<h3>', '</h3>');
  36. the_content();
  37. echo '</li>';
  38. endwhile; ?>
  39. </ul>
Add Comment
Please, Sign In to add comment