我为nav菜单页面制作了一个自定义菜单,以添加帖子类型的存档,就像帖子/页面等。我认为不可能让它更改站点url上的url url更改。您可以将url添加为/slug/
而不是http://url.com/slug/
, 但这对文件夹中的WordPress不起作用。
function add_post_types_nav_menu() {
add_meta_box(\'post_types_meta_box\', __( \'Post type archives\' ), \'render_add_post_types_nav_menu\', \'nav-menus\', \'side\', \'default\' );
}
add_action(\'admin_init\', \'add_post_types_nav_menu\');
function render_add_post_types_nav_menu() {
$post_types = get_post_types(array(\'public\' => true, \'_builtin\' => false), \'objects\', \'and\');
?>
<div id="posttype-archive" class="posttypediv">
<ul class="posttype-tabs add-menu-item-tabs">
<li class="tabs"><?php _e( \'Post types\' ); ?></li>
</ul>
<div class="tabs-panel tabs-panel-active">
<ul class="categorychecklist form-no-clear">
<?php $i = 0; foreach ($post_types as $post_type ) : $i++; ?>
<li>
<label class="menu-item-title"><input type="checkbox" class="menu-item-checkbox" name="menu-item[-<?php echo $i; ?>][menu-item-object-id]" value="<?php echo $post_type->name; ?>"> <?php echo $post_type->labels->name; ?></label>
<input type="hidden" class="menu-item-title" name="menu-item[-<?php echo $i; ?>][menu-item-title]" value="<?php echo $post_type->labels->name; ?>">
<input type="hidden" class="menu-item-url" name="menu-item[-<?php echo $i; ?>][menu-item-url]" value="<?php echo get_post_type_archive_link($post_type->name); ?>">
<input type="hidden" value="custom" name="menu-item[-<?php echo $i; ?>][menu-item-type]">
</li>
<?php endforeach; ?>
</ul>
</div>
<p class="button-controls">
<span class="list-controls">
<a href="/wp-admin/nav-menus.php?page-tab=all&selectall=1#posttype-archive" class="select-all">Select All</a>
</span>
<span class="add-to-menu">
<input type="submit" class="button-secondary submit-add-to-menu right" value="Add to Menu" name="add-post-type-menu-item" id="submit-posttype-archive">
<span class="spinner"></span>
</span>
</p>
</div>
<?php
}