我已创建此循环以获取最后添加的分类法类别帖子。这是代码
$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,但无法管理如何获得一个永久链接项目。帮我解决这个问题!
答案 0 :(得分:1)
使用
$permalink = get_permalink($mypost->ID);
echo $permalink ;
它会给你发帖&#39;永久
答案 1 :(得分:1)
在代码中添加“全局发布”功能似乎可以解决问题
像这样:$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>