我创建了一个自定义模板php文件,并制作了一个使用此模板的页面。
在这个模板中,我想显示我的博客文章,我复制了与首页相同的代码行来进行检索,但是没有用。
它显示了一个不可点击的链接,而不是我的博客文章:https://imgur.com/a/B9ohq96
我该如何解决?
我试图将代码自己放入页面中,但无效。
有list.php,我用作模板但没有用
<?php
/*
Template Name: list
*/
?>
<?php wp_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="blogo">
<h4> <?php the_category(); ?> <h4>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?> > See the post </a>
</div>
<?php endwhile;>
<?php wp_footer(); ?>
答案 0 :(得分:0)
在页面模板上,您需要调用wp_query循环以获取任何帖子类型的帖子。 我已经更新了您的代码,以使用页面模板-
在页面上获取帖子。<?php /* Template Name: list */ ?>
<?php
get_header();
$args = array(
'post_type' => 'post',
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="blogo">
<h4> <?php the_category(); ?> <h4>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" > See the post </a>
</div>
<?php
endwhile;
endif;
get_footer();
?>