📄 wp-menu.php
字号:
<?php/*Plugin Name: WP-MenuPlugin URI: http://www.vizioninteractive.com/Description: Customizable hook to pull Page Navigation into a theme. Page Exclusion, Inclusion, Site Map, Top Level, Secondary menus and moreAuthor: Vizion Interactive, IncVersion: 0.2.1Author URI: http://www.vizioninteractive.com/*/function wp_menu($args='',$over='',$custom='') { $ret = ""; parse_str($args,$params); $params['over'] = $over; // custom item effects; example: [onmouseover="dothis();" onmouseout="dothis();" style="inline-style:lol;"] if(!isset($params['return'])||($params['return']!=0&&$params['return']!=1)) { $params['return'] = 0; // options: 0 = off / 1 = on } if(is_array($custom)){$params['custom'] = $custom;} else{$params['custom'] = array();} $ret = wp_menu_run($params); if($params['return']==0) { print $ret; return; } return $ret; }function wp_menu_run($params='') { global $wp_query; if(!isset($params['nav_type'])||($params['nav_type']!="single"&&$params['nav_type']!="secondary"&&$params['nav_type']!="single_secondary"&&$params['nav_type']!="sitemap")) { $params['nav_type'] = "single"; // options: single / secondary / sitemap / single_secondary } if(!isset($params['nav_levels'])||(isset($params['nav_levels'])&&!is_numeric($params['nav_levels']))) { $params['nav_levels'] = 0; // options (int): 0 = all / 1+ = stop after level X } if(!isset($params['nav_tag'])||($params['nav_tag']!="ul"&&$params['nav_tag']!="ol"&&$params['nav_tag']!="dl")) { $params['nav_tag'] = "ul"; // options: ul / ol / dl } if(!isset($params['nav_class'])){$params['nav_class'] = "";} // assign a class="...." to navigation if(!isset($params['nav_id'])){$params['nav_id'] = "";} // assign an id="...." to navigation if(!isset($params['nav_wrap'])||($params['nav_wrap']!=0&&$params['nav_wrap']!=1)) { $params['nav_wrap'] = 1; // options: 0 = off / 1 = on } if(!isset($params['div'])||($params['div']!=0&&$params['div']!=1&&isset($params['div']))) { $params['div'] = 0; // div wrapper on menu (int) } if(!isset($params['div_class'])){$params['div_class'] = "";} // <div class="...."> if(!isset($params['div_id'])){$params['div_id'] = "";} // <div id="...."> if(!isset($params['heading'])||($params['heading']!="h2"&&$params['heading']!="dt"&&$params['heading']!=0)) { $params['heading'] = 0; // options: h2 / dt / 0 } if(!isset($params['this_id'])||(isset($params['this_id'])&&!is_int((int)$params['this_id']))) { $params['this_id'] = $wp_query->post->ID; // change the active ID (int) referenced } if(!isset($params['parent_id'])||(isset($params['parent_id'])&&!is_int((int)$params['parent_id']))) { $params['parent_id'] = 0; } if(!isset($params['parent_href'])) { $params['parent_href'] = wp_menu_get_href($params['parent_id']); // base the menus off of this href } if(!isset($params['link_titles'])||($params['link_titles']!=0&&$params['link_titles']!=1)) { $params['link_titles'] = 1; // options: 0 = off / 1 = on } if(!isset($params['active'])||($params['active']!="item"&&$params['active']!="link")) { $params['active'] = "item"; // options: item / link (this is what the selected class gets applied to) } if(!isset($params['active_class'])){$params['active_class'] = "selected";} // gets added to an item that is "active"; for example: class="selected" if(!isset($params['indent'])){$params['indent'] = "";} // just for the picky and OCD people -- \t character(s) to indent lines with; example: \t\t if(!isset($params['target'])){$params['target'] = "";} // <a href="/contact-us/" target="....">Link</a> if(!isset($params['accesskeys'])){$params['accesskeys'] = 1;} // Assign accesskeys; for example: accesskey="1" if(!isset($params['exclude'])){$params['exclude'] = array();} // Do not show these IDs else{$params['exclude'] = explode(",",$params['exclude']);} if(!isset($params['include'])){$params['include'] = array();} // Show only these IDs else{$params['include'] = explode(",",$params['include']);} if(!isset($params['exclude_uri'])) // If this URI is part of the link's URI, it will not be included { $params['exclude_uri'] = false; // options: false = off / thank-you = example URI exclusion } if(!isset($params['home_path'])){$params['home_path'] = '/home/';} // The real home link! if(!isset($params['home_link'])){$params['home_link'] = '/';} // What we want home to link to! $params['c2p_active']=0; if(!isset($params['c2p_cid'])){$params['c2p_cid'] = 0;} // Catgory ID for Category=Page (category called press releases) if(!isset($params['c2p_pid'])){$params['c2p_pid'] = 0;} // Page ID for Category=Page (page called press releases) $params['category_ids'] = wp_menu_get_categories(); if(in_array($params['c2p_cid'],$params['category_ids'])&&$params['c2p_cid']>0&&$params['c2p_pid']>0&&$wp_query->post->post_type=='post'){$params['c2p_active']=1;} $params['b2p_active']=0; if(!isset($params['b2p_pid'])){$params['b2p_pid'] = 0;} // Page ID for Blog (all posts) $params['secondary_id'] = $params['parent_id']; if($params['secondary_id']==0){$params['secondary_id'] = 'x';} if($params['b2p_pid']>0&&$wp_query->post->post_type=='post'){$params['b2p_active']=1;} $params['select_id'] = $params['parent_id']; $params['selected'] = 0; if($params['nav_type']=="secondary"||$params['nav_type']=="single_secondary") { $params['secondary_info'] = wp_menu_secondary_menu_links($params['secondary_id'],$params); } $params['indent_rec'] = $params['indent']; if($params['nav_type']=="secondary"){$params['select_id'] = 0;} $params['level'] = 0; $params['nav_applied'] = 0; $params['custom'] = wp_menu_custom($params); $params['is_custom'] = 0; if(!empty($params['custom'])){$params['is_custom']=1;} $params['children'] = wp_menu_tree($params); $ret = wp_menu_get($params); return $ret; }function wp_menu_custom($params) { if(empty($params['custom'])){return array();} $menu = $params['custom']; $ret = array(); foreach($menu as $item) { if(!isset($item['ID'])){$item['ID']='-1';} if(!isset($item['post_parent'])){$item['post_parent']='0';} if(!isset($item['children_ids'])){$item['children_ids']=array();} if(!isset($item['children'])){$item['children']=array();} if(isset($item['link_href'])&&isset($item['link_title'])) { $ret[] = $item; } } return $ret; }function wp_menu_get_categories() { $cats = get_the_category(); $cat_ids = array(); foreach($cats as $cat) { $cat_ids[] = (int)$cat->term_id; } return $cat_ids; }function wp_menu_item($item) { // in progress :-) }function wp_menu_tree($params,$sub=0) { global $wpdb; if(!empty($params['custom'])){return $params['custom'];} $ret = array(); $level = 0; if(isset($params['level'])){$level = $params['level'];} $level++; $ext = ""; $params['level'] = $level; $select_href = $params['parent_href']; if(isset($params['select_href'])){$select_href = $params['select_href'];} $params['select_href'] = $select_href; if($params['nav_type']=="secondary") { if($level==1) { if(!isset($params['secondary_info'])){$params['secondary_info'] = wp_menu_secondary_menu_links($params['secondary_id'],$params);} if($params['this_id']==$params['secondary_info']['full']['top']){$params['selected']=1;} $params['select_id'] = $params['secondary_info']['full']['top']; $params['select_href'] = $select_href = wp_menu_get_href($params['select_id']); } $ext1 = implode("','",$params['secondary_info']['matches']); $ext = " AND p.ID IN ('".$ext1."')"; } if(!empty($params['exclude'])) { $ext2 = implode("','",$params['exclude']); $ext .= " AND p.ID NOT IN ('".$ext2."')"; } if(!empty($params['include'])&&($params['nav_type']!="single"||$sub==0)) { $ext3 = implode("','",$params['include']); $ext .= " AND p.ID IN ('".$ext3."')"; } $result = $wpdb->get_results("SELECT t.term_id,t.slug,tax.parent,p.ID,p.post_name,p.post_title,p.post_parent,pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON pm.post_id=p.ID AND pm.meta_key='wp_menu_nav' LEFT JOIN $wpdb->terms AS t ON t.term_id=p.post_parent LEFT JOIN $wpdb->term_taxonomy AS tax ON tax.term_id=t.term_id WHERE p.post_parent='".$params['select_id']."' AND p.post_type='page' AND p.post_status='publish'".$ext." ORDER BY p.menu_order ASC"); $count = count($result); if($result&&0<$count) for($x=0;$x<$count;$x++) { $params['select_href'] = $select_href; $ret[$x] = array(); $ret[$x]['ID'] = $result[$x]->ID; $ret[$x]['post_parent'] = $result[$x]->post_parent; $ret[$x]['link_href'] = $params['select_href'].$result[$x]->post_name."/"; $params['select_href'] = $ret[$x]['link_href']; $ret[$x]['link_title'] = $result[$x]->post_title; $ret[$x]['children'] = $ret[$x]['children_ids'] = array(); if($params['select_id']!=$ret[$x]['ID']&&($params['nav_levels']==0||$level<$params['nav_levels'])&&(($params['nav_type']!="secondary")||$params['selected']!=1)) { $params['select_id'] = $ret[$x]['ID']; if(($params['this_id']==$params['select_id'])&&($params['nav_type']=="secondary")) { $params['selected'] = 1; } if(!is_array($params['secondary_info']['full']['current'])){$params['secondary_info']['full']['current'] = array();} if(in_array($ret[$x]['ID'],$params['secondary_info']['full']['current'])||$params['nav_type']=='sitemap') { $ret[$x]['children'] = wp_menu_tree($params,1); $ret[$x]['children_ids'] = wp_menu_children($ret[$x]['children']); $ret[$x]['children_ids'][] = $ret[$x]['ID']; } } else { $ret[$x]['children'] = $ret[$x]['children_ids'] = array(); } } return $ret; }function wp_menu_children($children,$arr=array()) { $count = count($children); for($x=0;$x<$count;$x++) { $arr[] = $children[$x]['ID']; if(!empty($children[$x]['children'])) { $arr = wp_menu_children($children[$x]['children'],$arr); } } return $arr; }function wp_menu_get_heading($id) { global $wpdb; $result = $wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE ID='".$id."'"); $count = count($result); $ret = ""; if($result&&0<$count) { $ret = $result[0]->post_title; } return $ret; }function wp_menu_get($params) { if(empty($params['children'])){return;} $ret = ""; $params['x'] = 0; if($params['div']==1) { $ret .= $params['indent']."<div"; if(!empty($params['div_class'])){$ret .= " class=\"".$params['div_class']."\"";} if(!empty($params['div_id'])){$ret .= " id=\"".$params['div_id']."\"";} $ret .= ">\n"; } if($params['heading']=="0"&&$params['nav_tag']=="ul") { $ret .= wp_menu_get_level($params['children'],$params); } else { $item_type = "li"; if($params['nav_tag']=="dl"){$item_type = "dd";} $indent = $params['indent'];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -