【问题标题】:WordPress Functions PHP issueWordPress 函数 PHP 问题
【发布时间】:2014-05-08 18:08:26
【问题描述】:

我不知道我做错了什么。当我使用以下代码时,除了底部的随机文本之外,实际上没有任何内容链接到页面:

<?php

    function salt_scripts() {
        //global $wp_styles;
        //wp_enqueue_style( 'stylesheet', 'netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
        //wp_enqueue_style( 'stylesheet', 'http://fonts.googleapis.com/css?family=Varela');


        // Loads main stylesheet
        wp_enqueue_style( 'style', get_stylesheet_uri() );
        wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css' );
        wp_enqueue_style( 'bootstrap-theme', get_template_directory_uri() . '/css/bootstrap-theme.min.css' );
        wp_enqueue_style( 'custom-styles', get_template_directory_uri() . '/css/custom-styles.css' );
    }

    add_action( 'wp_enqueue_scripts', 'salt_scripts' );

?>


LKDJFLSDKJFLSDKFJSLDKFJ WORK

我真的不知道还能尝试什么。我去过几十个网站,从默认的 WordPress 主题中窃取了代码位。

我的文件夹结构是这样的:

salt
    css
        bootstrap.css
        bootstrap-theme.min.css
        custom-styles.css
    img
    js

    style.css
    header.php
    index.php
    functions.php

这是我的 header.php 中的内容:

<body data-spy="scroll" data-target="#main-nav" data-offset="120">

<!-- Begin Main Nav-->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" id="main-nav">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="fa fa-bars"></span>
      </button>
      <a class="navbar-brand" href="#home"><img src="images/SaltSolutionsLogo.jpg" alt="SALT Solutions" /></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li><a href="#about" onclick="ga('send', 'event', 'Main Navigation', 'click', 'About Us');">About</a></li>
        <li><a href="#solutions" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Solutions');">Solutions</a></li>
        <li><a href="#casestudies" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Case Studies');">Case Studies</a></li>
        <li><a href="#resources" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Resources');">Resources</a></li>
        <li><a href="#calculate" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Calculate');">Calculate</a></li>
        <li><a href="#ourteam" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Our Team');">Our Team</a></li>
        <li><a href="#blog" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Blog');">Blog</a></li>
        <li><a href="#contact" onclick="ga('send', 'event', 'Main Navigation', 'click', 'Contact');">Contact</a></li>
      </ul>

      <ul class="nav navbar-nav navbar-right social-media hidden">
        <li><a href="#" target="_blank" onclick="ga('send', 'event', 'Social Media', 'click', 'Facebook');"><img src="images/facebook.png" alt="Facebook" /></a></li>
        <li><a href="#" target="_blank" onclick="ga('send', 'event', 'Social Media', 'click', 'Twitter');"><img src="images/twitter.png" alt="Twitter" /></a></li>
        <li><a href="#" target="_blank" onclick="ga('send', 'event', 'Social Media', 'click', 'GooglePLus');"><img src="images/googleplus.png" alt="Google+" /></a></li>
        <li><a href="#" target="_blank" onclick="ga('send', 'event', 'Social Media', 'click', 'LinkedIn');"><img src="images/linkedin.png" alt="LinkedIn" /></a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<!--End main-nav --> 

【问题讨论】:

  • 没有functions.php你把这段代码放在哪里?
  • 什么意思?此代码位于functions.php 中。如果不在functions.php中,我想它会在header.php或index.php中?
  • @NathanDawson 无论我把这段代码放在哪里,我都无法让它工作。我不知道该怎么办。
  • 我问是因为您没有在主题文件夹中显示 functions.php。
  • 请将 header.php 的内容也粘贴到您的问题中。

标签: php wordpress


【解决方案1】:

您缺少文档的顶部,这就是它不起作用的原因。

将以下内容添加到header.php 的顶部:

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <title><?php wp_title(); ?></title>
    <?php wp_head(); ?>
</head>

更多可以/应该去这里,但这将帮助您开始并解决您的 CSS 加载问题。

关闭footer.php中的HTML标签

&lt;/body&gt; 之前footer.php 添加&lt;?php wp_footer(); ?&gt;

例如

    <?php wp_footer(); ?>
</body>
</html>

【讨论】:

  • 它是 那是什么解决它。谢谢。我正在修剪 header.php 以尝试缩小问题范围。我添加了所有的文档类型和元信息。谢谢。
猜你喜欢
  • 2017-10-25
  • 2011-02-21
  • 2018-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
  • 2014-12-17
  • 2011-01-19
相关资源
最近更新 更多