Wordpress - 使用查询字符串值更新标题中的所有菜单链接 [英] Wordpress - Update ALL menu links in header with querystring value

查看:203
本文介绍了Wordpress - 使用查询字符串值更新标题中的所有菜单链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use wordpress to make a website replicate... So, when the viewer comes to http://www.wpsite.com/1005, I do a check (through an API) to see if the id is a valid/active rep, then set a cookie for the usual stuff (name, email, repid) and redirect to the main page:

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

我目前正在运行这一切。

I have all of this functioning currently.

所以此时,我想将id = 1005传递给页面顶部的所有菜单链接。我的网站正在使用wordpress中的Appearance - > Menus功能来构建菜单...

so at this point, I want to pass the "id=1005" to ALL of the menu links at the top of the page. My site is using the Appearance -> Menus functionality in wordpress to build the menu...

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

So when the viewer hovers over/clicks any link on the site, I want the "&id=1005" to be added to it. Is that possible? What if the user isn't valid and there is no "&id=1005"? Thanks.

Adam

更新:好的,我创建了一个助行课程,但我仍然感到很困惑将查询字符串id值放在每个值中:

Update: Ok, I create a walker class, but I am still confused where to put the querystring "id" value so it displays in each one:

// 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 );
 }
}

我感觉它在属性部分......那些带有那些高等教育表达的东西......比如如果不是''加上这个...但我错过了它...

I have a feeling it's in the "attributes" section... something with those tertiary expressions... Like "if id not ''" add THIS... but I'm missing it...

任何帮助非常感谢。

Adam

推荐答案

没有可用的过滤器修改 href atteribute。为此,您需要创建一个自定义助行器。并建立自己的菜单。这并不难。

There are no filters available to modify the href atteribute. To do this you need to create a custom walker. And build your own menu. It's not that hard to do.

更多信息:


  • 示例

  • < a href =http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-class/ =nofollow>教程

  • example
  • tutorial

这篇关于Wordpress - 使用查询字符串值更新标题中的所有菜单链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆