【问题标题】:wp_head(); crashing apache (xammp)wp_head();崩溃的 apache (xampp)
【发布时间】:2017-06-14 15:23:09
【问题描述】:

这里的第一个问题。我想知道你们是否可以帮助我。

所以我试图将一个静态的 Bootstrap 主题网站传递给一个动态的 CMS wordpress 网站。所以我用 html/css 编写了这个网站,把它展示给客户,现在我正在把它变成一个 wordpress 主题。现在这不是我创建的第一个 wordpress 网站,但我确实遇到了一个让我难过的问题。我正在尝试通过 wp_enqueue 函数系统链接所有样式表和脚本,这就是我迄今为止想出的:

函数.php

<?php
function wpt_theme_styles() {

  wp_enqueue_style('bootstrap' , get_template_directory_uri().'assets/css/bootstrap.min.css', array(), '1.0.0', 'all');
  wp_enqueue_style('font-awesome' , get_template_directory_uri() . 'assets/css/font-awesome.min.css', array(),'1.0.0', 'all');
  wp_enqueue_style('animate' , get_template_directory_uri() . 'assets/css/animate.css', array(),'1.0.0', 'all');
  wp_enqueue_style('font' , get_template_directory_uri() . 'assets/css/font.css', array(),'1.0.0', 'all');
  wp_enqueue_style('li-scroller' , get_template_directory_uri() . 'assets/css/li-scroller.css', array(),'1.0.0', 'all');
  wp_enqueue_style('slick' , get_template_directory_uri() . 'assets/css/slick.css', array(),'1.0.0', 'all');
  wp_enqueue_style('jquery_fancybox' , get_template_directory_uri() . 'assets/css/jquery.fancybox.css', array(), '1.0.0', 'all');
  wp_enqueue_style('theme' , get_template_directory_uri() . 'assets/css/theme.css', array(bootstrap),'1.0.0', 'all');
  wp_enqueue_style('style' , get_template_directory_uri() . 'style.css' , array(bootstrap),'1.0.0', 'all');

  wp_enqueue_scripts('wow', get_template_directory_uri() . 'assets/js/wow.mim/js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('bootstrap', get_template_directory_uri() . 'assets/js/bootstrap.min.js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('slick', get_template_directory_uri() . 'assets/js/slick.min.js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('jquery_li_scroller', get_template_directory_uri() . 'assets/js/jquery.li-scroller.1.0.js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('jquery_newsTicker', get_template_directory_uri() . 'assets/js/jquery.newsTicker.min.js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('jquery_fancybox_pack', get_template_directory_uri() . 'assets/js/jquery.fancybox.pack.js' , array('jquery'), '1.0.0', true);
  wp_enqueue_scripts('custom', get_template_directory_uri() . 'assets/js/custom.js' , array('jquery'), '1.0.0', true);


}

add_action("wp_enqueue_scripts", 'wpt_theme_styles');


?>

header.php

<!DOCTYPE html>
<html>
<head>
<title>8to Mandamiento</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>

我从未使用过这个函数,因此它可能非常粗糙或构造错误,但我一直在阅读,在标题中回显样式表不是链接它的正确形式。然而,当我尝试这个系统时,我得到的只是崩溃(https://imgur.com/a/2phNv

有人认为他们可以帮助我吗?

【问题讨论】:

  • 在不为wpt_theme_styles添加或执行操作的情况下是否可以工作?
  • @FahadKazmi 确实如此,但由于我没有执行操作,它似乎没有链接 JS/CSS

标签: javascript php css wordpress wordpress-theming


【解决方案1】:

好吧,我找到了自己问题的答案。这就是我要找的东西。

首先,我不应该直接将样式或脚本加入队列。在将样式或脚本排入队列之前,通常最好像这样注册样式/脚本:

    function octavomandamiento_styles() {
      /* Stylesheets */    
    wp_register_style('bootstrap', get_template_directory_uri().'/assets/css/bootstrap.min.css');
            wp_enqueue_style('bootstrap', get_template_directory_uri().'/assets/css/bootstrap.min.css', array(''), null, all);
...
... /*Rest of the styles*/
...}

add_action("wp_enqueue_scripts", 'octavomandamiento_styles');

为了完整起见,我也会展示一个脚本示例

function octavomandamiento_scripts() {
  /* Scripts */

  wp_register_script('wow', get_template_directory_uri().'/js/wow.min.js');
    wp_enqueue_script('wow',  get_template_directory_uri() . '/js/wow.mim/js' , array('jquery'), null, true);
...
.../*rest of the function*/
...}

add_action("wp_enqueue_scripts", 'octavomandamiento_scripts');

然后脚本应该在您放置的位置正确加载:

<?php wp_head(); ?>
/* and */
<?php wp_footer(); ?>

应该分别放在header.phpfooter.php 中。

其次我尝试在一个函数上同时使用两个队列,但这只是继续在我身上弹出错误。我确信可以一次性完成所有操作,但我真的无法弄清楚为什么它不工作,老实说它仍然可以正常加载。

最后,我的入队脚本中有一个 sintaxis 错误。您会看到,当您编写函数并入队和注册脚本时,您应该输入:

wp_register_script('wow', get_template_directory_uri().'/js/wow.min.js');
    wp_enqueue_script('wow',  get_template_directory_uri() . '/js/wow.mim/js' , array('jquery'), null, true);

我已经放了

wp_enqueue_scripts('wow', get_template_directory_uri() . 'assets/js/wow.mim/js' , array('jquery'), '1.0.0', true);

你发现错误了吗?我花了一段时间才弄明白。入队和注册时必须使用单数 script,但在调用 wp_enqueue 操作时,必须使用复数 scripts。事后看来,这似乎很合乎逻辑,但哦,好吧。你生活和学习。

希望这篇文章对遇到此问题或任何其他排队问题的人有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-12
    • 2016-04-23
    • 1970-01-01
    • 2015-03-27
    • 2011-09-10
    • 2015-07-10
    • 2017-10-20
    • 1970-01-01
    相关资源
    最近更新 更多