【发布时间】:2017-11-21 10:32:03
【问题描述】:
我创建了一个名为新闻的自定义帖子类型并添加了某些新闻。现在我想在存档页面中显示它。我在函数文件中添加了 'has_archive' => 'true'。 我的存档页面代码是:
<?php
$args = array('post_type' => 'news',
'post_status' => 'publish');
$news=wp_get_recent_posts($args);
?>
<div class="container mc_tb_p">
<h1>NEWS/RELEASES</h1>
<?php
foreach ($news as $row)
{
$id = $row['ID'];
$ntitle = $row['post_title'];
$ncontent = $row['post_content'];
$ncontent = strip_tags($ncontent);
if (strlen($ncontent) > 100)
{
$stringCut = substr($ncontent, 0, 200).'... <a href="'.get_permalink($id).'">Read More</a>';
}
else{
$stringCut = $row['post_content'];
}
$ndate = $row['post_date'];
$trim = new DateTime($ndate);
$trimdate = $trim->format('d-m-Y');
// var_dump($trimdate);
?>
<div class="news_releases">
<a href="<?php echo get_permalink($id)?>"><h3><?php echo $ntitle?></h3></a>
<h5><i>Published On: <?php echo $trimdate?></i></h5>
<p><?php echo $stringCut;?></p>
</div>
<?php
}
?>
</div>
现在当我给出我的网址时:https//sitename/news ...它显示了第二条新闻的单页,没有别的,我已经尝试了一切,但似乎没有任何效果。请帮助
【问题讨论】: