如何在WordPress中显示自定义页面模板中的帖子?
问题描述:
我想使我的自定义页面模板,其中我显示帖子与自定义样式,我不知道如何显示帖子在这个自定义页面模板,在这里我附上我的自定义页面模板的简单代码。如何在WordPress中显示自定义页面模板中的帖子?
<?php
/*
Template Name: Custom Template
*/
get_header();
//custom code for post is here
get_footer();
?>
答
您可以随时使用类似网页模板,并充分利用代码在我们自己的类和风格,你写在这里指的是:
<?php
/*
Template Name: Custom Template
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while (have_posts()) : the_post(); ?>
<header class="entry-header">
<?php the_post_thumbnail(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php comments_template('', true); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
+0
谢谢你的回答 – Avi
答
您可以使用WP_Query()
向您的页面模板添加自定义循环。您可以在WordPress的法典找了几个例子:https://codex.wordpress.org/Class_Reference/WP_Query
它非常简单您首先添加一个页面并将其分配给您刚刚创建的模板并使用简单的循环,或者您可以使用WP Query在其中添加您想要添加的所有样式并为其获得乐趣。可以帮助你immensly https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/ – sagar