admin管理员组文章数量:1391991
So in a local wordpress I created a plugin that will make a row with its custom post type called book (it is saving successfully in the db)... and now I want to display a special template for it in the index of my theme, but after I use this code nothing shows:
<?php
$loop = new WP_Query( array( 'post_type' => 'book', 'category_name' => 'book', 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
////
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="ptitle">
<h2><?php echo get_the_title(); ?></h2>
</div>
<h3> <?php the_title(); ?> </h3>
<small>Posted on:<?php the_time('F j, Y'); ?>, in
<?php the_category(); ?> </small>
<p> <?php the_content(); ?> </p>
<hr>
<?php
endwhile;
endif;
?>
So in a local wordpress I created a plugin that will make a row with its custom post type called book (it is saving successfully in the db)... and now I want to display a special template for it in the index of my theme, but after I use this code nothing shows:
<?php
$loop = new WP_Query( array( 'post_type' => 'book', 'category_name' => 'book', 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
////
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="ptitle">
<h2><?php echo get_the_title(); ?></h2>
</div>
<h3> <?php the_title(); ?> </h3>
<small>Posted on:<?php the_time('F j, Y'); ?>, in
<?php the_category(); ?> </small>
<p> <?php the_content(); ?> </p>
<hr>
<?php
endwhile;
endif;
?>
Share
Improve this question
edited Feb 11, 2020 at 16:12
Cheo Molina
asked Feb 11, 2020 at 16:03
Cheo MolinaCheo Molina
155 bronze badges
1
|
1 Answer
Reset to default 0The loops itself is working. I guess you have trouble to output this content on some page template. There are many ways how to show output of this loop on the homepage.
1.You can create home.php
file, put there your code and in theme settings select which page should output your custom post type.
2.You can create page template according to the documentation, put there your code, create some page in wordpress admin and on the right side in editor menu choose your newly created template.
本文标签: phpVisualize info in just custom posttype in theme
版权声明:本文标题:php - Visualize info in just custom post_type in theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744758210a2623590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP_Query()
? If you set up asingle-cptslug.php
file in the theme, it will already automatically be running a query for you, which you can modify withpre_get_posts
if needed. – WebElaine Commented Feb 11, 2020 at 16:30