Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress-使用querystring值更新标题中的所有菜单链接_Wordpress_Url_Menu_Query String_Hyperlink - Fatal编程技术网

Wordpress-使用querystring值更新标题中的所有菜单链接

Wordpress-使用querystring值更新标题中的所有菜单链接,wordpress,url,menu,query-string,hyperlink,Wordpress,Url,Menu,Query String,Hyperlink,我正在尝试使用wordpress制作一个网站复制。。。因此,当查看器打开时,我(通过API)检查id是否为有效/活动的代表,然后为常用内容(姓名、电子邮件、代表id)设置cookie并重定向到主页: 目前,我已经完成了所有这些功能 现在,我想把“id=1005”传递给页面顶部的所有菜单链接。我的网站正在使用wordpress中的外观->菜单功能来构建菜单 因此,当查看器悬停/单击站点上的任何链接时,我希望将“&id=1005”添加到其中。可能吗?如果用户无效并且没有“&id=1005”怎么办?

我正在尝试使用wordpress制作一个网站复制。。。因此,当查看器打开时,我(通过API)检查id是否为有效/活动的代表,然后为常用内容(姓名、电子邮件、代表id)设置cookie并重定向到主页:

目前,我已经完成了所有这些功能

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

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

亚当

更新:好的,我创建了一个walker类,但我仍然不知道将querystring“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 );
 }
}
//沃克导航菜单
类说明\u walker扩展了walker\u导航菜单
{
函数开始(&$output、$item、$depth、$args)
{
全局$wp_查询;
$indent=($depth)?str_repeat(“\t”,$depth):”;
$class_name=$value='';
$classes=空($item->classes)?array():(array)$item->classes;
$class_name=join(“”,应用_过滤器('nav_menu_css_class',数组_过滤器($classes),$item));
$class_names='class=“”.esc_attr($class_names)。”;
$output.=$indent.'
  • '; $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=''; $append=''; $description=!empty($item->description)?“”.esc_attr($item->description)。“”; 如果($depth!=0) { $description=$append=$prepend=“”; } $item_output=$args->before; $item_输出=''; $item\u output.=$args->link\u before.$prepend.apply\u过滤器('the\u title',$item->title,$item->ID)。$append; $item\u output.=$description.$args->link\u after; $item_输出=''; $item_output.=$args->after; $output.=apply_filters('walker_nav_menu_start_el'、$item_output、$item、$depth、$args); } }
  • 我感觉它在“属性”部分。。。一些第三级表达式的东西。。。如“如果id不是“””添加此。。。但是我错过了

    感谢您的帮助


    Adam

    没有可用于修改
    href
    属性的筛选器。为此,您需要创建一个。并建立自己的菜单。这并不难做到

    更多信息:


    您好,简,非常感谢您的链接!这是其中一件事,有人只需要告诉你,你不能按照你想要的方式来做:)我会尝试一下,并分享我的结果。再次感谢!这是可能的,给它一个机会,当你卡住了让我知道。建议,如果可能的话,将
    id
    重命名为更具意义的名称。非常感谢您的帮助!我创建了一个walker,但是我仍然不知道我把querystring“id”值放在哪里连接。。。添加了上面的代码。对于查看此内容的其他人。。。如果您使用的不是wordpress股票模板,他们很可能有一个自定义的walker文件。。。我的位于theme function.php。。。