php 最新的帖子菜单项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 最新的帖子菜单项相关的知识,希望对你有一定的参考价值。
/**
* Look for placeholder url and replace it with latest post
*
* @param $items
*
* @return mixed
*/
function latest_conference_item( $items ) {
// Get the latest conference
$latestpost = get_posts( array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'post_type' => 'post'
) );
foreach ( $items as $item ) {
if ( empty( $latestpost ) || '#placeholder' != $item->url ) {
continue;
}
// Replace the placeholder with the real URL
$item->url = get_permalink( $latestpost[0]->ID ) . 'program';
}
return $items;
}
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'latest_conference_item', 10 );
}
以上是关于php 最新的帖子菜单项的主要内容,如果未能解决你的问题,请参考以下文章