WordPress建站教程:不同的分类显示不同的菜单

前端之家收集整理的这篇文章主要介绍了WordPress建站教程:不同的分类显示不同的菜单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在使用wordpress建站的过程中,我们想在不同的分类显示不同的菜单,今天我们就介绍一下给电影分类(别名:movies)和电子书分类(别名:books)添加自己的导航菜单。原理是先通过 register_my_menus() 这个函数注册电影和电子书导航位置,再通过 wp_nav_menu() 函数调用

第一步:切换到主题,打开functions.PHP文件,加入以下代码注册导航菜单位置

Crayon-5c891d2c29a96404912750" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d2c29a96404912750-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29a96404912750-2">2
Crayon-num" data-line="Crayon-5c891d2c29a96404912750-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29a96404912750-4">4
Crayon-num" data-line="Crayon-5c891d2c29a96404912750-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29a96404912750-6">6
Crayon-num" data-line="Crayon-5c891d2c29a96404912750-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29a96404912750-8">8
Crayon-num" data-line="Crayon-5c891d2c29a96404912750-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29a96404912750-10">10
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d2c29a96404912750-1">Crayon-c">//激活WP导航菜单
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29a96404912750-2">Crayon-t">functionCrayon-h"> Crayon-e">register_my_menusCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d2c29a96404912750-3">Crayon-h"> Crayon-e">register_nav_menusCrayon-sy">(
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29a96404912750-4">Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-h">
Crayon-line" id="Crayon-5c891d2c29a96404912750-5">Crayon-h"> Crayon-s">'default-menu'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'默认导航'Crayon-h"> Crayon-sy">)Crayon-sy">,Crayon-h"> Crayon-c">//注册默认导航位置
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29a96404912750-6">Crayon-h"> Crayon-s">'books-menu'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'电子书导航'Crayon-h"> Crayon-sy">)Crayon-sy">,Crayon-h"> Crayon-c">//注册电子书导航位置
Crayon-line" id="Crayon-5c891d2c29a96404912750-7">Crayon-h"> Crayon-s">'movies-menu'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-h"> Crayon-s">'电影导航'Crayon-h"> Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-c">//注册电影导航位置
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29a96404912750-8">Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d2c29a96404912750-9">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29a96404912750-10">Crayon-e">add_actionCrayon-sy">(Crayon-h"> Crayon-s">'init'Crayon-sy">,Crayon-h"> Crayon-s">'register_my_menus'Crayon-h"> Crayon-sy">)Crayon-sy">;

第二步:在不同分类调用不同位置的菜单

Crayon-5c891d2c29aa1472792666" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d2c29aa1472792666-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29aa1472792666-2">2
Crayon-num" data-line="Crayon-5c891d2c29aa1472792666-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29aa1472792666-4">4
Crayon-num" data-line="Crayon-5c891d2c29aa1472792666-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2c29aa1472792666-6">6
Crayon-num" data-line="Crayon-5c891d2c29aa1472792666-7">7
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d2c29aa1472792666-1">Crayon-ta">PHPCrayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">in_categoryCrayon-sy">(Crayon-s">"movies"Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29aa1472792666-2">Crayon-h">Crayon-ta">PHPCrayon-h"> Crayon-e">wp_nav_menuCrayon-sy">(Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-h"> Crayon-s">'theme_location'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'movies-menu'Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line" id="Crayon-5c891d2c29aa1472792666-3">Crayon-ta">PHPCrayon-h"> Crayon-sy">}Crayon-h"> Crayon-st">elseifCrayon-sy">(Crayon-h"> Crayon-e">in_categoryCrayon-sy">(Crayon-s">"books"Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29aa1472792666-4">Crayon-h">Crayon-ta">PHPCrayon-h"> Crayon-e">wp_nav_menuCrayon-sy">(Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-h"> Crayon-s">'theme_location'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'books-menu'Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line" id="Crayon-5c891d2c29aa1472792666-5">Crayon-ta">PHPCrayon-h"> Crayon-sy">}Crayon-h"> Crayon-st">elseCrayon-h"> Crayon-sy">{Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d2c29aa1472792666-6">Crayon-h">Crayon-ta">PHPCrayon-h"> Crayon-e">wp_nav_menuCrayon-sy">(Crayon-h"> Crayon-t">arrayCrayon-sy">(Crayon-h"> Crayon-s">'theme_location'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'default-menu'Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line" id="Crayon-5c891d2c29aa1472792666-7">Crayon-ta">PHPCrayon-h"> Crayon-sy">}Crayon-h">

猜你在找的wordpress相关文章