PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Hilfe Wordpress wirft Parse Fehler aus
Beitrag
<blockquote data-quote="Vagant" data-source="post: 2172864" data-attributes="member: 412571"><p><strong>AW: Hilfe Wordpress wirft Parse Fehler aus</strong></p><p></p><p>Hier mal der vollständige Code:</p><p></p><p><?php </p><p></p><p>function theme_get_menu($args = '')</p><p>{</p><p> $args = wp_parse_args( $args, array('source' => 'Pages', 'depth' => 0, 'menu' => null, 'class' => ''));</p><p> $source = &$args['source'];</p><p> $menu = &$args['menu'];</p><p> if (function_exists('get_nav_menu_locations') && $menu != null && is_string($menu)) { // theme location</p><p> $location = theme_get_array_value(get_nav_menu_locations(), $menu);</p><p> if ($location) {</p><p> $menu = wp_get_nav_menu_object($location);</p><p> if($menu) $source = 'Custom Menu';</p><p> } </p><p> }</p><p></p><p> if ($source == 'Custom Menu' && function_exists('wp_nav_menu') && $menu != null) {</p><p> return theme_get_list_menu($args); </p><p> } </p><p> </p><p> if ($source == 'Pages') {</p><p> return theme_get_list_pages(array_merge(array('sort_column' => 'menu_order, post_title'), $args)); </p><p> }</p><p> </p><p> if ($source == 'Categories') {</p><p> return theme_get_list_categories(array_merge(array('title_li'=> false), $args));</p><p> }</p><p>}</p><p></p><p>/* custom menu */</p><p>function theme_get_list_menu($args = array()) {</p><p> global $wp_query;</p><p> $menu_items = wp_get_nav_menu_items($args['menu']->term_id);</p><p> if(empty($menu_items)) return ''; </p><p> $home_page_id = (int) get_option('page_for_posts');</p><p> $queried_object_id = (int) $wp_query->queried_object_id;</p><p> $active_ID = null;</p><p> </p><p> $IdToKey = array();</p><p> foreach ( (array) $menu_items as $key => $menu_item ) {</p><p> $IdToKey[$menu_item->ID] = $key;</p><p> if ($menu_item->object_id == $queried_object_id && </p><p> (</p><p> ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||</p><p> ( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||</p><p> ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ))</p><p> )</p><p> ) </p><p> {</p><p> $active_ID = $menu_item->ID;</p><p> } elseif ( 'custom' == $menu_item->object ) {</p><p> if ( theme_is_current_url($menu_item->url)) {</p><p> $active_ID = $menu_item->ID;</p><p> }</p><p> }</p><p> }</p><p></p><p> $current_ID = $active_ID;</p><p> while ($current_ID && isset($IdToKey[$current_ID])) {</p><p> $activeIDs[] = $current_ID;</p><p> $current_item = &$menu_items[$IdToKey[$current_ID]];</p><p> $current_item->classes[] = 'active';</p><p> $current_ID = $current_item->menu_item_parent;</p><p> }</p><p></p><p> $sorted_menu_items = array();</p><p> foreach ((array) $menu_items as $key => $menu_item) {</p><p> $sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item);</p><p> }</p><p></p><p> $items = array();</p><p> foreach ($sorted_menu_items as $el) {</p><p> $id = $el->db_id;</p><p> $title = $el->title;</p><p> $classes = empty( $el->classes ) ? array() : (array) $el->classes;</p><p> $active = in_array('active', $classes); </p><p> $items[] = new theme_MenuItem(array(</p><p> 'id' => $id,</p><p> 'active' => $active,</p><p> 'attr' => array(</p><p> 'title' => (empty($el->attr_title) ? $title : $el->attr_title),</p><p> 'target' => $el->target,</p><p> 'rel' => $el->xfn,</p><p> 'href' => $el->url,</p><p> 'class' => join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $el))</p><p> ),</p><p> 'title' => $title,</p><p> 'parent' => $el->menu_item_parent</p><p> )); </p><p> }</p><p> </p><p> $walker = new theme_MenuWalker();</p><p> $items = $walker->walk($items, $args);</p><p> $items = apply_filters('wp_nav_menu_items', $items, $args);</p><p> $items = apply_filters("wp_nav_menu_{$menu->slug}_items", $items, $args);</p><p> return apply_filters('wp_nav_menu', $items, $args);</p><p>}</p><p></p><p>/* pages */</p><p>function theme_get_list_pages($args = array()) {</p><p> global $wp_query;</p><p> $pages = &get_pages($args);</p><p> if (empty($pages)) return '';</p><p> </p><p> $IdToKey = array();</p><p> $currentID = null;</p><p></p><p> foreach ($pages as $key => $page)</p><p> {</p><p> $IdToKey[$page->ID] = $key;</p><p> }</p><p></p><p> if ($wp_query->is_page) {</p><p> $currentID = $wp_query->get_queried_object_id();</p><p> }</p><p></p><p> $frontID = null;</p><p> $blogID = null;</p><p> </p><p> if ('page' == get_option('show_on_front')) {</p><p></p><p> $frontID = get_option('page_on_front');</p><p> if ($frontID && isset($IdToKey[$frontID])) {</p><p> $frontKey = $IdToKey[$frontID];</p><p> $frontPage = $pages[$frontKey];</p><p> unset($pages[$frontKey]);</p><p> $frontPage->post_parent = 0;</p><p> $frontPage->menu_order = 0;</p><p> array_unshift($pages, $frontPage);</p><p> $IdToKey = array();</p><p> foreach ($pages as $key => $page)</p><p> {</p><p> $IdToKey[$page->ID] = $key;</p><p> }</p><p> }</p><p></p><p> if (is_home()) {</p><p> $blogID = get_option('page_for_posts');</p><p> if ($blogID && isset($IdToKey[$blogID])) </p><p> {</p><p> $currentID = $blogID;</p><p> }</p><p> }</p><p> }</p><p></p><p> $active_Id = $currentID;</p><p> $activeIDs = array();</p><p> while($active_Id && isset($IdToKey[$active_Id]))</p><p> {</p><p> $active = $pages[$IdToKey[$active_Id]];</p><p> if ($active && $active->post_status == 'private') break;</p><p> $activeIDs[] = $active->ID;</p><p> $active_Id = $active->post_parent;</p><p> }</p><p> </p><p> $items = array();</p><p> if (theme_get_option('theme_menu_showHome') && ('page' != get_option('show_on_front') || (!get_option('page_on_front') && !get_option('page_for_posts'))))</p><p> { </p><p> $title = theme_get_option('theme_menu_homeCaption');</p><p> $active = is_home();</p><p> $items[] = new theme_MenuItem(array(</p><p> 'id' => 'home',</p><p> 'active' => $active,</p><p> 'attr' => array('class' => ($active ? 'active' : ''), 'href' => get_home_url(), 'title' => $title),</p><p> 'title' => $title,</p><p> )); </p><p> }</p><p> foreach ($pages as $page) {</p><p> $id = $page->ID;</p><p> $title = $page->post_title;</p><p> $active = in_array($id, $activeIDs); </p><p> $href = (($frontID && $frontID == $id) ? get_option('home') : get_page_link($id));</p><p> $separator = theme_get_meta_option($id, 'theme_show_as_separator');</p><p> if ($separator) {</p><p> $href = '#';</p><p> }</p><p> $items[] = new theme_MenuItem(array(</p><p> 'id' => $id,</p><p> 'active' => $active,</p><p> 'attr' => array('class' => ($active ? 'active' : ''), 'href' => $href, 'title' => $title),</p><p> 'title' => $title,</p><p> 'parent' => $page->post_parent</p><p> )); </p><p> }</p><p> </p><p> $walker = new theme_MenuWalker();</p><p> return $walker->walk($items, $args);</p><p>}</p><p></p><p>/* categories */</p><p>function theme_get_list_categories($args = array()) {</p><p> global $wp_query, $post;</p><p> $categories = &get_categories($args);</p><p> if (empty($categories)) return '';</p><p> $IdToKey = array();</p><p> foreach ($categories as $key => $category){</p><p> $IdToKey[$category->term_id] = $key;</p><p> }</p><p></p><p> $currentID = null;</p><p> if ($wp_query->is_category)</p><p> {</p><p> $currentID = $wp_query->get_queried_object_id();</p><p> }</p><p></p><p> $activeID = $currentID;</p><p> $activeIDs = theme_get_category_branch($currentID, $categories, $IdToKey);</p><p> if(theme_get_option('theme_menu_highlight_active_categories') && is_single()){</p><p> foreach((get_the_category($post->ID)) as $cat) { </p><p> $activeIDs = array_merge($activeIDs, theme_get_category_branch($cat->term_id, $categories, $IdToKey));</p><p> } </p><p> }</p><p> $items = array();</p><p> foreach ($categories as $category) {</p><p> $id = $category->term_id;</p><p> $title = $category->name;</p><p> $desc = (($category->description) ? $category->description : sprintf(__('View all posts in %s', THEME_NS), $title));</p><p> $active = in_array($id, $activeIDs);</p><p> $items[] = new theme_MenuItem(array(</p><p> 'id' => $id,</p><p> 'active' => $active,</p><p> 'attr' => array('class' => ($active ? 'active' : ''), 'href' => get_category_link($id), 'title' => $desc),</p><p> 'title' => $title,</p><p> 'parent' => $category->parent</p><p> )); </p><p> }</p><p> </p><p> $walker = new theme_MenuWalker();</p><p> return $walker->walk($items, $args);</p><p>}</p><p></p><p>//Helper, return array( 'id', 'parent_id', ... , 'root_id' )</p><p>function theme_get_category_branch($id, $categories, $IdToKey) {</p><p> $result = array();</p><p> while ($id && isset($IdToKey[$id])) {</p><p> $result[] = $id; </p><p> $id = $categories[$IdToKey[$id]]->parent;</p><p> }</p><p> return $result;</p><p>}</p><p></p><p></p><p>/* menu item */</p><p>class theme_MenuItem {</p><p> var $id;</p><p> var $active;</p><p> var $parent;</p><p> var $attr;</p><p> var $title;</p><p> </p><p> function theme_MenuItem($args = '') {</p><p> $args = wp_parse_args($args, </p><p> array(</p><p> 'id' => '',</p><p> 'active' => false,</p><p> 'parent' => 0,</p><p> 'attr' => '',</p><p> 'title' => '',</p><p> )</p><p> );</p><p> $this->id = $args['id'];</p><p> $this->active = $args['active'];</p><p> $this->parent = $args['parent'];</p><p> $this->attr = $args['attr'];</p><p> $this->title = $args['title'];</p><p> }</p><p> </p><p> function get_start($level) {</p><p> $class = ($this->active ? 'active' : '');</p><p> $title = apply_filters('the_title', $this->title, $this->id);</p><p> if (theme_get_option('theme_menu_trim_title')) </p><p>{</p><p> $title = theme_trim_long_str($title, theme_get_option($level == 0 ? 'theme_menu_trim_len' : 'theme_submenu_trim_len'))</p><p> }</p><p> return str_repeat("\t", $level+1) </p><p> . '<li' . theme_prepare_attr(array('class' => $class)) . '>' </p><p> . '<a' . theme_prepare_attr($this->attr) . '>' </p><p> . ($level == 0 ? '<span class="l"> </span><span class="r"> </span><span class="t">' : '') </p><p> . $title </p><p> . ($level == 0 ? '</span>' : '')</p><p> . '</a>'. "\n";</p><p> } </p><p> </p><p> function get_end($level){</p><p> return str_repeat("\t", $level+1) . '</li>' . "\n";</p><p> }</p><p>}</p><p></p><p>/* menu walker */</p><p>class theme_MenuWalker {</p><p> </p><p> var $child_Ids = array();</p><p> var $IdToKey = array();</p><p> var $level = 0;</p><p> var $items;</p><p> var $depth;</p><p> var $args;</p><p> var $class;</p><p> </p><p> function walk($items = array(), $args = '') {</p><p> $args = wp_parse_args($args, array('depth' => 0, 'class' => ''));</p><p> $this->items = &$items;</p><p> $this->depth = (int)$args['depth'];</p><p> $this->class = $args['class'];</p><p> foreach($items as $key => $item) {</p><p> $this->IdToKey[$item->id] = $key;</p><p> if (!isset($this->child_Ids[$item->parent])) {</p><p> $this->child_Ids[$item->parent] = array();</p><p> }</p><p> $parent = $item->parent;</p><p> if (!$parent) $parent = 0;</p><p> $this->child_Ids[$parent][] = $item->id;</p><p> }</p><p> </p><p> $output = '';</p><p> if (isset($this->child_Ids[0])) {</p><p> $this->display($output, $this->child_Ids[0]);</p><p> }</p><p> if (theme_is_empty_html($output)) return '';</p><p> return "\n" .'<ul' .theme_prepare_attr(array('class' => $this->class)) .'>' ."\n" .$output .'</ul>'."\n";</p><p> }</p><p> </p><p> function display(&$output, $child_Ids) {</p><p> if (!is_array($child_Ids)) return;</p><p> $first = true;</p><p> foreach($child_Ids as $child_Id){</p><p> if (!isset($this->IdToKey[$child_Id])) continue;</p><p> $item = $this->items[$this->IdToKey[$child_Id]];</p><p> if ($this->class == 'art-hmenu' && !$first && $this->level == 0) {</p><p> $output .= "\t" .'<li class="art-hmenu-li-separator"><span class="art-hmenu-separator"> </span></li>' . "\n";</p><p> }</p><p> if ($this->class == 'art-vmenu') {</p><p> if ($this->level == 0) { </p><p> if(!$first) {</p><p> $output .= "\t" .'<li class="art-vmenu-separator"><span class="art-vmenu-separator-span"> </span></li>' . "\n";</p><p> }</p><p> } else {</p><p> if(($this->level == 1) && $first) {</p><p> $output .= "\t" .'<li class="art-vmenu-separator art-vmenu-separator-first"><span class="art-vmenu-separator-span"> </span></li>' . "\n";</p><p> } else {</p><p> $output .= "\t" .'<li class="art-vsubmenu-separator"><span class="art-vsubmenu-separator-span"> </span></li>' . "\n";</p><p> }</p><p> } </p><p> }</p><p> $output .= $item->get_start($this->level);</p><p> if (</p><p> ($this->depth == 0 || $this->level < ($this->depth-1)) </p><p> && isset($this->child_Ids[$item->id]) </p><p> && (count($this->child_Ids[$item->id]) > 0)</p><p> ) {</p><p> $this->level++;</p><p> $output .= str_repeat("\t", $this->level) . '<ul' . theme_prepare_attr(array('class' => ($item->active ? 'active' : ''))) . '>' . "\n";</p><p> $this->display($output, $this->child_Ids[$item->id]);</p><p> $output .= str_repeat("\t", $this->level) . '</ul>' . "\n";</p><p> $this->level--;</p><p> }</p><p> $output .= $item->get_end($this->level);</p><p> $first = false;</p><p> }</p><p> }</p><p> </p><p>}</p><p></p><p>// Not support old wp version</p><p>if (WP_VERSION < 3.0) return;</p><p>function theme_get_pages( $pages ) {</p><p> if(is_admin()) return $pages;</p><p></p><p> $excluded_option = get_option('theme_show_in_menu');</p><p> if (!$excluded_option || !is_array($excluded_option)) return $pages;</p><p> $excluded_ids = array();</p><p> foreach ($excluded_option as $id => $show)</p><p> {</p><p> if(!$show) {</p><p> $excluded_ids[] = $id; </p><p> }</p><p> }</p><p> $excluded_parent_ids = array();</p><p> foreach ($pages as $page) {</p><p> </p><p> $title = theme_get_meta_option($page->ID, 'theme_title_in_menu');</p><p> if ($title) {</p><p> $page->post_title = $title;</p><p> }</p><p> </p><p> if (in_array($page->ID, $excluded_ids)){</p><p> $excluded_parent_ids[$page->ID] = $page->post_parent;</p><p> }</p><p> }</p><p></p><p> $length = count($pages);</p><p> for ( $i=0; $i<$length; $i++ ) {</p><p> $page = & $pages[$i];</p><p> if (in_array($page->post_parent, $excluded_ids)) {</p><p> $page->post_parent = theme_get_array_value($excluded_parent_ids, $page->post_parent, $page->post_parent);</p><p> }</p><p> if (in_array($page->ID, $excluded_ids)) {</p><p> unset( $pages[$i] );</p><p> }</p><p> }</p><p></p><p> if ( ! is_array( $pages ) ) $pages = (array) $pages;</p><p> $pages = array_values( $pages );</p><p></p><p> return $pages;</p><p>}</p><p>add_filter('get_pages','theme_get_pages');</p></blockquote><p></p>
[QUOTE="Vagant, post: 2172864, member: 412571"] [b]AW: Hilfe Wordpress wirft Parse Fehler aus[/b] Hier mal der vollständige Code: <?php function theme_get_menu($args = '') { $args = wp_parse_args( $args, array('source' => 'Pages', 'depth' => 0, 'menu' => null, 'class' => '')); $source = &$args['source']; $menu = &$args['menu']; if (function_exists('get_nav_menu_locations') && $menu != null && is_string($menu)) { // theme location $location = theme_get_array_value(get_nav_menu_locations(), $menu); if ($location) { $menu = wp_get_nav_menu_object($location); if($menu) $source = 'Custom Menu'; } } if ($source == 'Custom Menu' && function_exists('wp_nav_menu') && $menu != null) { return theme_get_list_menu($args); } if ($source == 'Pages') { return theme_get_list_pages(array_merge(array('sort_column' => 'menu_order, post_title'), $args)); } if ($source == 'Categories') { return theme_get_list_categories(array_merge(array('title_li'=> false), $args)); } } /* custom menu */ function theme_get_list_menu($args = array()) { global $wp_query; $menu_items = wp_get_nav_menu_items($args['menu']->term_id); if(empty($menu_items)) return ''; $home_page_id = (int) get_option('page_for_posts'); $queried_object_id = (int) $wp_query->queried_object_id; $active_ID = null; $IdToKey = array(); foreach ( (array) $menu_items as $key => $menu_item ) { $IdToKey[$menu_item->ID] = $key; if ($menu_item->object_id == $queried_object_id && ( ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )) ) ) { $active_ID = $menu_item->ID; } elseif ( 'custom' == $menu_item->object ) { if ( theme_is_current_url($menu_item->url)) { $active_ID = $menu_item->ID; } } } $current_ID = $active_ID; while ($current_ID && isset($IdToKey[$current_ID])) { $activeIDs[] = $current_ID; $current_item = &$menu_items[$IdToKey[$current_ID]]; $current_item->classes[] = 'active'; $current_ID = $current_item->menu_item_parent; } $sorted_menu_items = array(); foreach ((array) $menu_items as $key => $menu_item) { $sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item); } $items = array(); foreach ($sorted_menu_items as $el) { $id = $el->db_id; $title = $el->title; $classes = empty( $el->classes ) ? array() : (array) $el->classes; $active = in_array('active', $classes); $items[] = new theme_MenuItem(array( 'id' => $id, 'active' => $active, 'attr' => array( 'title' => (empty($el->attr_title) ? $title : $el->attr_title), 'target' => $el->target, 'rel' => $el->xfn, 'href' => $el->url, 'class' => join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $el)) ), 'title' => $title, 'parent' => $el->menu_item_parent )); } $walker = new theme_MenuWalker(); $items = $walker->walk($items, $args); $items = apply_filters('wp_nav_menu_items', $items, $args); $items = apply_filters("wp_nav_menu_{$menu->slug}_items", $items, $args); return apply_filters('wp_nav_menu', $items, $args); } /* pages */ function theme_get_list_pages($args = array()) { global $wp_query; $pages = &get_pages($args); if (empty($pages)) return ''; $IdToKey = array(); $currentID = null; foreach ($pages as $key => $page) { $IdToKey[$page->ID] = $key; } if ($wp_query->is_page) { $currentID = $wp_query->get_queried_object_id(); } $frontID = null; $blogID = null; if ('page' == get_option('show_on_front')) { $frontID = get_option('page_on_front'); if ($frontID && isset($IdToKey[$frontID])) { $frontKey = $IdToKey[$frontID]; $frontPage = $pages[$frontKey]; unset($pages[$frontKey]); $frontPage->post_parent = 0; $frontPage->menu_order = 0; array_unshift($pages, $frontPage); $IdToKey = array(); foreach ($pages as $key => $page) { $IdToKey[$page->ID] = $key; } } if (is_home()) { $blogID = get_option('page_for_posts'); if ($blogID && isset($IdToKey[$blogID])) { $currentID = $blogID; } } } $active_Id = $currentID; $activeIDs = array(); while($active_Id && isset($IdToKey[$active_Id])) { $active = $pages[$IdToKey[$active_Id]]; if ($active && $active->post_status == 'private') break; $activeIDs[] = $active->ID; $active_Id = $active->post_parent; } $items = array(); if (theme_get_option('theme_menu_showHome') && ('page' != get_option('show_on_front') || (!get_option('page_on_front') && !get_option('page_for_posts')))) { $title = theme_get_option('theme_menu_homeCaption'); $active = is_home(); $items[] = new theme_MenuItem(array( 'id' => 'home', 'active' => $active, 'attr' => array('class' => ($active ? 'active' : ''), 'href' => get_home_url(), 'title' => $title), 'title' => $title, )); } foreach ($pages as $page) { $id = $page->ID; $title = $page->post_title; $active = in_array($id, $activeIDs); $href = (($frontID && $frontID == $id) ? get_option('home') : get_page_link($id)); $separator = theme_get_meta_option($id, 'theme_show_as_separator'); if ($separator) { $href = '#'; } $items[] = new theme_MenuItem(array( 'id' => $id, 'active' => $active, 'attr' => array('class' => ($active ? 'active' : ''), 'href' => $href, 'title' => $title), 'title' => $title, 'parent' => $page->post_parent )); } $walker = new theme_MenuWalker(); return $walker->walk($items, $args); } /* categories */ function theme_get_list_categories($args = array()) { global $wp_query, $post; $categories = &get_categories($args); if (empty($categories)) return ''; $IdToKey = array(); foreach ($categories as $key => $category){ $IdToKey[$category->term_id] = $key; } $currentID = null; if ($wp_query->is_category) { $currentID = $wp_query->get_queried_object_id(); } $activeID = $currentID; $activeIDs = theme_get_category_branch($currentID, $categories, $IdToKey); if(theme_get_option('theme_menu_highlight_active_categories') && is_single()){ foreach((get_the_category($post->ID)) as $cat) { $activeIDs = array_merge($activeIDs, theme_get_category_branch($cat->term_id, $categories, $IdToKey)); } } $items = array(); foreach ($categories as $category) { $id = $category->term_id; $title = $category->name; $desc = (($category->description) ? $category->description : sprintf(__('View all posts in %s', THEME_NS), $title)); $active = in_array($id, $activeIDs); $items[] = new theme_MenuItem(array( 'id' => $id, 'active' => $active, 'attr' => array('class' => ($active ? 'active' : ''), 'href' => get_category_link($id), 'title' => $desc), 'title' => $title, 'parent' => $category->parent )); } $walker = new theme_MenuWalker(); return $walker->walk($items, $args); } //Helper, return array( 'id', 'parent_id', ... , 'root_id' ) function theme_get_category_branch($id, $categories, $IdToKey) { $result = array(); while ($id && isset($IdToKey[$id])) { $result[] = $id; $id = $categories[$IdToKey[$id]]->parent; } return $result; } /* menu item */ class theme_MenuItem { var $id; var $active; var $parent; var $attr; var $title; function theme_MenuItem($args = '') { $args = wp_parse_args($args, array( 'id' => '', 'active' => false, 'parent' => 0, 'attr' => '', 'title' => '', ) ); $this->id = $args['id']; $this->active = $args['active']; $this->parent = $args['parent']; $this->attr = $args['attr']; $this->title = $args['title']; } function get_start($level) { $class = ($this->active ? 'active' : ''); $title = apply_filters('the_title', $this->title, $this->id); if (theme_get_option('theme_menu_trim_title')) { $title = theme_trim_long_str($title, theme_get_option($level == 0 ? 'theme_menu_trim_len' : 'theme_submenu_trim_len')) } return str_repeat("\t", $level+1) . '<li' . theme_prepare_attr(array('class' => $class)) . '>' . '<a' . theme_prepare_attr($this->attr) . '>' . ($level == 0 ? '<span class="l"> </span><span class="r"> </span><span class="t">' : '') . $title . ($level == 0 ? '</span>' : '') . '</a>'. "\n"; } function get_end($level){ return str_repeat("\t", $level+1) . '</li>' . "\n"; } } /* menu walker */ class theme_MenuWalker { var $child_Ids = array(); var $IdToKey = array(); var $level = 0; var $items; var $depth; var $args; var $class; function walk($items = array(), $args = '') { $args = wp_parse_args($args, array('depth' => 0, 'class' => '')); $this->items = &$items; $this->depth = (int)$args['depth']; $this->class = $args['class']; foreach($items as $key => $item) { $this->IdToKey[$item->id] = $key; if (!isset($this->child_Ids[$item->parent])) { $this->child_Ids[$item->parent] = array(); } $parent = $item->parent; if (!$parent) $parent = 0; $this->child_Ids[$parent][] = $item->id; } $output = ''; if (isset($this->child_Ids[0])) { $this->display($output, $this->child_Ids[0]); } if (theme_is_empty_html($output)) return ''; return "\n" .'<ul' .theme_prepare_attr(array('class' => $this->class)) .'>' ."\n" .$output .'</ul>'."\n"; } function display(&$output, $child_Ids) { if (!is_array($child_Ids)) return; $first = true; foreach($child_Ids as $child_Id){ if (!isset($this->IdToKey[$child_Id])) continue; $item = $this->items[$this->IdToKey[$child_Id]]; if ($this->class == 'art-hmenu' && !$first && $this->level == 0) { $output .= "\t" .'<li class="art-hmenu-li-separator"><span class="art-hmenu-separator"> </span></li>' . "\n"; } if ($this->class == 'art-vmenu') { if ($this->level == 0) { if(!$first) { $output .= "\t" .'<li class="art-vmenu-separator"><span class="art-vmenu-separator-span"> </span></li>' . "\n"; } } else { if(($this->level == 1) && $first) { $output .= "\t" .'<li class="art-vmenu-separator art-vmenu-separator-first"><span class="art-vmenu-separator-span"> </span></li>' . "\n"; } else { $output .= "\t" .'<li class="art-vsubmenu-separator"><span class="art-vsubmenu-separator-span"> </span></li>' . "\n"; } } } $output .= $item->get_start($this->level); if ( ($this->depth == 0 || $this->level < ($this->depth-1)) && isset($this->child_Ids[$item->id]) && (count($this->child_Ids[$item->id]) > 0) ) { $this->level++; $output .= str_repeat("\t", $this->level) . '<ul' . theme_prepare_attr(array('class' => ($item->active ? 'active' : ''))) . '>' . "\n"; $this->display($output, $this->child_Ids[$item->id]); $output .= str_repeat("\t", $this->level) . '</ul>' . "\n"; $this->level--; } $output .= $item->get_end($this->level); $first = false; } } } // Not support old wp version if (WP_VERSION < 3.0) return; function theme_get_pages( $pages ) { if(is_admin()) return $pages; $excluded_option = get_option('theme_show_in_menu'); if (!$excluded_option || !is_array($excluded_option)) return $pages; $excluded_ids = array(); foreach ($excluded_option as $id => $show) { if(!$show) { $excluded_ids[] = $id; } } $excluded_parent_ids = array(); foreach ($pages as $page) { $title = theme_get_meta_option($page->ID, 'theme_title_in_menu'); if ($title) { $page->post_title = $title; } if (in_array($page->ID, $excluded_ids)){ $excluded_parent_ids[$page->ID] = $page->post_parent; } } $length = count($pages); for ( $i=0; $i<$length; $i++ ) { $page = & $pages[$i]; if (in_array($page->post_parent, $excluded_ids)) { $page->post_parent = theme_get_array_value($excluded_parent_ids, $page->post_parent, $page->post_parent); } if (in_array($page->ID, $excluded_ids)) { unset( $pages[$i] ); } } if ( ! is_array( $pages ) ) $pages = (array) $pages; $pages = array_values( $pages ); return $pages; } add_filter('get_pages','theme_get_pages'); [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ▲ = 5, ▼ = 2 und ■ = 7, was ist ▲ × ▼ + ■?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Hilfe Wordpress wirft Parse Fehler aus
Oben