Wordpress - 使用查询字符串值更新标题中的所有菜单链接

时间:2012-11-27 11:04:43

标签: wordpress url menu query-string hyperlink

我正在尝试使用wordpress来复制网站...所以,当观众来到http://www.wpsite.com/1005时,我会检查(通过API)以查看该ID是否是有效/有效的代表,然后为通常的东西(名称,电子邮件,repid)设置一个cookie并重定向到主页面:

http://www.wpsite.com/wp/?page_id=34&id=1005

我目前所有这一切都在运作。

所以在这一点上,我想将“id = 1005”传递给页面顶部的所有菜单链接。我的网站正在使用外观 - >在wordpress中使用菜单功能来构建菜单...

因此,当观众悬停/点击网站上的任何链接时,我希望将“& id = 1005”添加到其中。那可能吗?如果用户无效并且没有“& id = 1005”怎么办?感谢。

亚当

更新:好的,我创建了一个walker类,但我仍然感到困惑,在哪里放置查询字符串“id”值,以便它显示在每一个:

// Walker Nav Menu
class description_walker extends Walker_Nav_Menu
{
     function start_el(&$output, $item, $depth, $args)
 {
       global $wp_query;
       $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
       $class_names = $value = '';
       $classes = empty( $item->classes ) ? array() : (array) $item->classes;
       $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
       $class_names = ' class="'. esc_attr( $class_names ) . '"';
       $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
       $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
       $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
       $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
       $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
       $prepend = '<b>';
       $append = '</b>';
       $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
       if($depth != 0)
       {
                 $description = $append = $prepend = "";
       }
        $item_output = $args->before;
        $item_output .= '<a'. $attributes .'>';
        $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
        $item_output .= $description.$args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
 }
}

我感觉它出现在“属性”部分......那些带有这些高级表达式的东西......就像“if id not''”添加这个...但我错过了它......

感谢任何帮助。

亚当

1 个答案:

答案 0 :(得分:1)

没有可用于修改href atteribute的过滤器。为此,您需要创建custom walker。并建立自己的菜单。这并不难。

更多信息: