如何仅将标题和日期添加到文字新闻上的博客文章



我是WordPress的新手,我试图只在博客文章中显示标题和发布日期。我在谷歌搜索和狂欢时找不到任何答案。目前,无论在哪个页面上,它都会显示页面的标题和创建日期。

这是我正在使用的索引代码:

<?php get_header(); ?>
<div id="main"><br><br>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(__('(more...)')); ?></p>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<br> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>

我知道它正在调用每一页上的标题和短语"发布于"。我想知道如何让它到达它只会在我的博客文章中显示它们的地方。

提前谢谢你。

更好的方法是编辑与相应页面相关的模板文件。

在当前代码中,您可以在循环中检查当前帖子的帖子类型。然后有条件地显示标题和日期。

<?php get_header(); ?>
<div id="main"><br><br>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $postType = get_post_type();
if($postType == 'post'){ ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
<p><?php the_content(__('(more...)')); ?></p>
<?php if($postType == 'post'){ ?>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<?php } ?>
<br> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>

最新更新