【问题标题】:wordpress posts doesn't retrieve on custom templatewordpress 帖子无法在自定义模板上检索
【发布时间】:2019-07-25 14:32:03
【问题描述】:

我创建了一个自定义模板 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(); ?>

【问题讨论】:

    标签: php wordpress templates


    【解决方案1】:

    在页面模板上,您需要调用 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();
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-20
      • 2013-11-10
      • 1970-01-01
      相关资源
      最近更新 更多