We use custom post types on nearly every site we develop, from sliders to products, custom post types make it a lot easier to separate content so your client finds it easier to maintain their WordPress website.
Creating a WordPress loop for a custom post type is easy and just needs this simple snippet instead of the normal WordPress loop. It’s best to create a WordPress page template to put this code into as you typically don’t want it to be in the normal WordPress files such as index.php, page.php, single.php or archive.php. I would suggest creating a copy of your themes page.php and then save it as template-younamehere.php. You can then replace the normal WordPress loop with the following code and then assign this to a particular page you want the new post type to appear on. You will need to add a template header to the file first of course, you can find the code snippet for this by clicking here.
<?php $loop = new WP_Query( array( 'post_type' => 'yourposttypehere' // This is the name of your post type - change this as required, 'posts_per_page' => 50 // This is the amount of posts per page you want to show ) ); while ( $loop->have_posts() ) : $loop->the_post(); // The content you want to loop goes in here: ?> <div class="col-sm-4"> My column content </div> <?php endwhile; wp_reset_postdata(); ?>
To break this down into English, this is what is happening here:
Hope you find this WordPress snippet useful.
How do you go about growing your agency? Do you rely on repeat business and…
Following on from yesterday's post “if you want to be tougher, be tougher”, this is…
We were recently asked by someone why we relatively expensive and charged more than someone else…
We are pleased to announce that our first e-book is now available to download on…
A nice mix this week of Wordpress guides and e-commerce posts make up this weeks…
GDPR features today and this is going to be a hot topic in WordPress and…
This website uses cookies.