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 最新的帖子菜单项的主要内容,如果未能解决你的问题,请参考以下文章

在 Wordpress 中显示存档帖子

使用 ajax 通过 WordPress 菜单在 div 中按类别加载最新帖子

自定义帖子类型活动菜单项

显示每个类别的最新帖子的下拉导航菜单

使用 Wordpress,我如何创建一个链接到自定义帖子类型存档的新菜单项?

php 重命名菜单更改帖子管理菜单中的帖子