Ok, I installed the Custom Post Type UI plugin and create one. I then added a new post to it. In my theme, i have a piece of code like this:
<?php
$loop = new WP_Query( array(
'post_type' => 'case studies', /* edit this line */
'posts_per_page' => 15 ) );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php endwhile; ?>
Now, firstly if i click the thumbnail, i get an error in the browser saying it’s in a redirect loop, but secondly I’d like to know exactly what files i need to create to view a single post of this custom post type. And what to put in that file.
Use
single-{posttype}.php
for the single template. Also, if you register your post type with thehas_archive
argument set totrue
, then you can usearchive-{posttype}.php
for your archive template, which will allow you to skip that query that you have there, since the global$wp_query
object will already be populated with your custom post type.BTW, you have a space in your
post_type
argument, which will be a problem.Check out the Template Hierarchy, and consider registering your CPTs using code in a plugin rather than using a CPT UI plugin.
There’s no need as WordPress will use the default page template however you can create a custom single-cpt.php file where cpt is the name of your registered post type.
You could just write this into your single.php file (within the loop) and echo out whatever fields you need within the if statement.
Another option is t0 create a page template. Copy your single.php file and rename it case_studies.php .. at the top within php tags add:
and then add the same if statement within the single.php loop as the above example…
Custom Post Type in wordpress.Basic four steps.Step1: File Path location : theme/function.php in your theme.Paste code in function.php (register custom post type )
Step2: how can show wordpress custom post type in wordpress template page ?
You can show anywhere in template page like this :
Step3: Create new template for show single post like this
single-{custom post type name}.php
or
single-services.php
Step4: Paste code in single-services.php file
This is custom post type example with single post page.