繁体   English   中英

如何在JSON文件中调用Wordpress get_stylesheet_directory_uri()

[英]How do I call Wordpress get_stylesheet_directory_uri() in JSON file

首先,我对Java绝望,对JSON一无所知。

我目前正在建立一个网站,并将微粒.js整合到设计中。 但是,搜索几天后,我不知所措,如何才能将get_stylesheet_directory_uri()函数调用到JSON配置文件中。

通过全局在header.php文件中声明一个js变量,我能够找出如何在particles.js和particles-app.js中做到这一点,但是对于JSON,我不知道。

这是我需要称呼它的地方:

  "image": {
    "src": "sprites/blueBlur.png",
    "width": 100,
    "height": 100
  }

如果我将其保留原样,则它仅指向根Wordpress文件。

整个JSON文件为:

    {
  "particles": {
    "number": {
      "value": 43,
      "density": {
        "enable": true,
        "value_area": 800
      }
    },
    "color": {
      "value": "#00ffd8"
    },
    "shape": {
      "type": "image",
      "stroke": {
        "width": 0,
        "color": "#000"
      },
      "polygon": {
        "nb_sides": 6
      },
      "image": {
        "src": "sprites/blueBlur.png",
        "width": 100,
        "height": 100
      }
    },
    "opacity": {
      "value": 1,
      "random": true,
      "anim": {
        "enable": false,
        "speed": 1,
        "opacity_min": 0.1,
        "sync": false
      }
    },
    "size": {
      "value": 2,
      "random": false,
      "anim": {
        "enable": true,
        "speed": 10,
        "size_min": 40,
        "sync": false
      }
    },
    "line_linked": {
      "enable": false,
      "distance": 200,
      "color": "#ffffff",
      "opacity": 1,
      "width": 2
    },
    "move": {
      "enable": true,
      "speed": 1.9,
      "direction": "none",
      "random": true,
      "straight": false,
      "out_mode": "out",
      "bounce": false,
      "attract": {
        "enable": false,
        "rotateX": 600,
        "rotateY": 1200
      }
    }
  },
  "interactivity": {
    "detect_on": "canvas",
    "events": {
      "onhover": {
        "enable": false,
        "mode": "grab"
      },
      "onclick": {
        "enable": false,
        "mode": "push"
      },
      "resize": true
    },
    "modes": {
      "grab": {
        "distance": 400,
        "line_linked": {
          "opacity": 1
        }
      },
      "bubble": {
        "distance": 400,
        "size": 40,
        "duration": 2,
        "opacity": 8,
        "speed": 3
      },
      "repulse": {
        "distance": 200,
        "duration": 0.4
      },
      "push": {
        "particles_nb": 4
      },
      "remove": {
        "particles_nb": 2
      }
    }
  },
  "retina_detect": true
}

问候迈克尔

由于网址是在标头中分配给全局JS变量的,因此您可以像这样在JSON对象中调用/附加网址。

var url = 'http://example.com/wp-content/themes/twentysixteen';

var json = {
  "image": {
    "src": url + "sprites/blueBlur.png",
    "width": 100,
    "height": 100
  }
};

console.log(json);

您可以通过使用PHP使用样式表的直接url。

喜欢

<?php echo $_SERVER['SERVER_NAME']; ?>/wp-content/themes/your_theme/style_directory/file.css

可能会对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM