我有那个网站:http://ougk.gr我希望在导航上有一个指向特定类别的最新帖子的链接(带评论的完整帖子等).我怎样才能做到这一点?
pai*_*lee 11
有几种方法可以做到这一点.这个使用wp_get_recent_posts(),并打印一个基本链接:
<nav>
<?php
$args = array( 'numberposts' => '1', 'category' => CAT_ID );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<a href="' . get_permalink($recent["ID"]) . '">Latest Post</a>';
}
?>
// .. other menu code ..
</nav>
Run Code Online (Sandbox Code Playgroud)
CAT_ID
目标类别的ID 在哪里.对于您的情况,简单的答案是在打开导航标记之后插入链接代码,如上所述.
要将链接放在导航中的其他位置,您将不得不深入研究您粘贴的代码中调用的其他一些函数.弄脏你的手可能是个好主意..
<?php
$args = array(
'numberposts' => '1',
);
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ):
$post_id = $recent['ID'];
$post_url = get_permalink($recent['ID']);
$post_title = $recent['post_title'];
$post_content = $recent['post_content'];
$post_thumbnail = get_the_post_thumbnail($recent['ID']);
endforeach;
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17454 次 |
最近记录: |