Reputation: 3
I have created a custom post type named as product. After that I have created a template file to show all products on that page and write the below code :
<?php $loop = new WP_Query( array( 'post_type' => 'acme_product',
'posts_per_page' => 14 ) );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div>
<div>
<?php the_post_thumbnail('thumbnail');
?>
</div>
<div>
<?php the_title( '<h2 class="entry-title"><a href="'.get_permalink().'" title="'.
the_title_attribute( 'echo=0' ).
'" rel="bookmark">', '</a></h2>' );
?>
</div>
</div>
<?php endwhile;
?>
But when I click on the product title link it will not show my product details page. Can anyone help me?
Upvotes: 0
Views: 1481
Reputation: 8809
You need to save your template as single-{post_type}.php
so in your case it would be single-acme_product.php
and make sure that permalink is enable if not than
as per your code you don't need to define the post_type
here. just use with simple code
<?php while ( have_posts() ) : the_post(); ?>
Upvotes: 1
Reputation: 396
It sounds as though you've already figured out how to loop through your product type. If you're new to custom post types and are not already aware of it, I would suggest investigating the "archive" template for custom post types (archive-{post_type}.php). I saw another answer that referenced single-{post_type}.php as well; both of these can be identified in the Template Hierarchy documentation in the WP Codex. By default, if you don't provide a customized single template for your post type, it will fall back to single.php (which may require customization if you want it to perform double-duty for multiple post types).
With that in mind, and assuming you're already using single-product.php in your theme (or have otherwise coaxed Wordpress into using your template), it would be helpful to know the symptoms you're experiencing:
Without clear details on what symptoms you're actually experiencing, it's hard to give you better direction. Hopefully some of this information points you to the correct answer, but if not please share additional details as to what is happening on your end.
Upvotes: 0