【问题标题】:Post not displaying in wordpress theme帖子未在 wordpress 主题中显示
【发布时间】:2016-06-23 05:08:10
【问题描述】:

我正在 wordpress 中进行主题集成。我创建了 home.php(模板页面)并从后端选择(用于前端页面)。 现在我想在首页显示帖子。我将以下代码用于在首页显示帖子。但代码不起作用。我错在哪里? 这是我的代码

<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); 
  the_content(); 
endwhile; 
endif; 
?>

【问题讨论】:

  • 你能粘贴代码吗?我想你忘记添加代码了。
  • @Tejas Shah : 这是我的代码

标签: wordpress wordpress-theming


【解决方案1】:

您可以使用以下代码 -

<?php
$args = array('posts_per_page' => 3, 'post__not_in' => get_option('sticky_posts'));
$the_query = new WP_Query($args);

if ($the_query->have_posts()) :
    while ($the_query->have_posts()) : $the_query->the_post(); ?>                          

        <a href="<?php the_permalink(); ?>"><?php esc_html(the_title()); ?></a>       

        <?php the_excerpt(); ?>
    <?php
     endwhile; ?>
<?php wp_reset_postdata(); ?>

<?php endif; ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2015-08-07
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多