admin管理员组文章数量:1279042
I am trying to wrap my head around custom post types. What I am trying to achieve is a simple branch listing. There is a dealers menu that has drop downs with regions. When you click on a region I just want it to list branches within the region. Nothing fancy, no maps, just plain text with branch name and contact details + address. Something like this:
Branch Name
Contact Person
Address
Contact number
Branch Name 2
Contact Person 2
Address 2
Contact number 2
I have used custom post UI plugin and another one that lets me add this data in the backend. I can't for the life of me figure out how to display it in the frontend.
I don't want it to act like a post where it lists everything and you click on it for more detail. It should just display as above when you click on a region from the dropdown. Is there a plugin that would do this or do you have to hard code it?
I am trying to wrap my head around custom post types. What I am trying to achieve is a simple branch listing. There is a dealers menu that has drop downs with regions. When you click on a region I just want it to list branches within the region. Nothing fancy, no maps, just plain text with branch name and contact details + address. Something like this:
Branch Name
Contact Person
Address
Contact number
Branch Name 2
Contact Person 2
Address 2
Contact number 2
I have used custom post UI plugin and another one that lets me add this data in the backend. I can't for the life of me figure out how to display it in the frontend.
I don't want it to act like a post where it lists everything and you click on it for more detail. It should just display as above when you click on a region from the dropdown. Is there a plugin that would do this or do you have to hard code it?
Share Improve this question asked Dec 1, 2014 at 5:36 Iggy's PopIggy's Pop 1151 gold badge2 silver badges8 bronze badges 3 |3 Answers
Reset to default 2You can do that easy on this way, just duplicate single.php
and rename to single-custom-post-type-name.php
like single-cars.php
, same thing with archive or taxonomy, taxonomy-taxonomy-name.php
or archive-taxonomy-name.php
Or you can make your query for random page, home or blog:
<?php
// The Query
$query = new WP_Query(array('post_type' => 'your-custom-post'));
query_posts( $query );
// The Loop
while ( $query->have_posts() ) : $query->the_post();
// your post content ( title, excerpt, thumb....)
endwhile;
// Reset Query
wp_reset_query();
?>
Good luck! ;)
?php while (have_posts()) : the_post(); ?>
<?php
$args = array('post_type' => 'employee', '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();?>
<?php endwhile;
wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
endwhile;
?>
Try It and Good Luck
$args = array( 'post_type' => 'your custom post name', 'post_status' => 'publish', 'posts_per_page' => 10, ); $arr_posts = new WP_Query( $args ); if ( $arr_posts->have_posts() ) : while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); echo the_title(); endwhile;endif; wp_reset_postdata();
本文标签: Displaying custom post types in front end
版权声明:本文标题:Displaying custom post types in front end 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741275166a2369686.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
archive-{$post-type}.php
. That's all. It's the core thing. :) – Mayeenul Islam Commented Dec 1, 2014 at 5:55