dsf12313 2016-09-15 17:15
浏览 30

将if / else窗口宽度子句添加到Wordpress navwalker.php

The goal here is to make a Wordpress boostrap main menu top level item which has sub-items act as a clickable link for devices > 768 px wide and retain the default behavior for small device.

There is the following code in the navwalker.php file around line 83:

// If item has_children add atts to a.
if ( $args->has_children && $depth === 0 ) {
    $atts['href'] = '#';
    $atts['data-toggle'] = 'dropdown';
    $atts['class'] = 'dropdown-toggle';
}

To make the link clickable for normal screens I need to modify the code but then add an else statement so that it retains the default behavior, something like:

// If item has_children add atts to a.
if ( $args->has_children && $depth === 0 ) { 
    if ( $windowwidth < 768) {
        $atts['href'] = '#';
        $atts['data-toggle'] = 'dropdown';
        $atts['class'] = 'dropdown-toggle';
    } else {
        $atts['href'] = ! empty( $item->url ) ? $item->url : ''; 
        //$atts['data-toggle'] = 'dropdown';
        $atts['class'] = 'dropdown-toggle';
    }       
}

The question is how to obtain the $windowwidth, presumably in JavaScript, so that I can use it in a PHP if/else clause.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题