我自定义了我的模板,并试图将html转换为wordpress模板,我创建了一个页面网格。php。我想用图片展示我所有的帖子。但我不知道怎么做。以及我的脚本放在哪里。当您查看所有帖子时,我的html具有DiverNet背景色。有谁能帮我指点迷津吗?
如何在我的页面中显示所有帖子-grid.php模板页面
2 个回复
最合适的回答,由SO网友:DHL17 整理而成
<?php
$args = array(
\'post_type\' => \'put your custom PostType name here\',
\'posts_per_page\' => \'-1\'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Contents of the queried post results go here.
}
}
// Restore original post data.
wp_reset_postdata();
?>
SO网友:Jitender Singh
您可以使用wordpressWP_Query 类循环浏览所有帖子。
<?php
// the query
$args = array(\'post_type\'=> \'post\')
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php the_posts_navigation(); ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
或者,如果您是wordpress新手,那么您可以创建任何wordpress主题的子主题,您可以使用wordpress代码并根据需要修改它。真正的儿童主题是wordpress的一个很好的概念,可以很容易地制作主题。希望这会有所帮助!
结束