我创建了这个循环,用于获取最后添加的分类类别帖子。这是代码
$issue = get_terms('articles-tax','orderby=Desc&order=ASC');
$latest_edition = $issue[0]->slug;
$latest_edition = $issue[0]->term_id;
$postsart = get_posts(array(
'showposts' => -1,
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'articles-tax',
'field' => 'term_id',
'terms' => $latest_edition)
)) ); foreach ($postsart as $mypost) { ?>
<div class="article_item"><div class="article_title"><?php echo $mypost->post_title?></div><div class="article_short_content"> <?php echo $mypost->post_excerpt ?> </div>
<div class="news_border"></div>
<div class="news_readmore"><a href="<?php ?>">Read More</a></div>
</div>
所以现在我无法获得帖子的永久链接,不知道如何从数组中获取。已经做了$mypost的var_dump,但无法管理如何获得一个项目永久链接。请帮我解决这个问题!
使用
$permalink = get_permalink($mypost->ID);
echo $permalink ;
它将为您提供帖子的永久链接
在代码中添加"global-post"函数似乎可以实现
像这样:
$postsart = get_posts(array(
'showposts' => -1,
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'articles-tax',
'field' => 'term_id',
'terms' => $latest_edition)
)) );
global $post;
foreach ($postsart as $post) {
setup_postdata($post);
?>
<div class="article_item"><div class="article_title"><?php echo $post->post_title?></div><div class="article_short_content"> <?php echo $post->post_excerpt ?> </div>
<div class="news_border"></div>
<div class="news_readmore"><a href="<?php echo get_the_permalink($post->ID); ?>">Read More</a></div>
</div>