我曾尝试将HTML网站转换为WordPress,但仅​​显示内容且CSS无法正常运行

时间:2019-08-14 20:21:53

标签: html css wordpress

我希望将HTML网站转换为具有相同主题的WordPress网站。

我已经在WordPress的functions.php文件中添加了“ wp_enqueue_style”以查找CSS文件,但仍然无法正常工作。

  1. functions.php
<?php

function our_theme_dependencies(){ ?>

    <script>alert("its working"); </script>

    <?php

    //css libraries
    wp_enqueue_style('main-style', get_stylesheet_directory_uri().'/assets/css/style.css');
    wp_enqueue_style('bootstrap-style', get_stylesheet_directory_uri().'/assets/css/jquery.bxslider.css');
    wp_enqueue_style('plugin-set', get_stylesheet_directory_uri().'/assets/css/plugin.css');

}

add_action('wp_enqueue_scripts', 'our_theme_dependencies');

?>
  1. front-page.php
<?php get_header(); ?>

        <div class="notice-board-row">
            <div class="container notice-board-container">
                <div class="notice-board-wraper">
                    <h3>Notice Board</h3>
                    <div class="notice-board-slider">
                        <div class="notice-item">
                            <div class="date">
                                <span class="month">Jan</span>
                                <span class="no">22</span>
                                <span class="year">2020</span>
                            </div>

<?php get_footer(); ?>

我希望将与网站HTML版本相同的主题转换为WordPress网站。

2 个答案:

答案 0 :(得分:1)

converted html page to wordpress

css无法正常工作

答案 1 :(得分:0)

1。。确保已在wp_head()文件中调用了header.php

header.php必须与

相似
<html>
<head>
<!-- Your content -->
<?php wp_head(); ?>
</head>
<body>
<!-- Your content -->

您的文件footer.php需要关闭正文和html标记,还需要调用wp_footer() f.e.您的footer.php必须与

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

2。。我建议将get_stylesheet_directory_uri().'/assets/css/style.css'替换为get_theme_file_uri('/assets/css/style.css')

3。。尝试使用版本参数f.e更改css文件的版本。

wp_enqueue_style(
'main-style',
get_theme_file_uri('assets/css/style.css')
[],
'1.0.0'
);

然后在进行更改后增加版本。从1.0.01.0.1,依此类推。

css文件的新版本阻止了浏览器缓存旧文件。

我建议在functions.php文件顶部使用资产版本常量,例如。

define('YOUR_THEME_NAME_ASSETS_VERSION', '1.0.1'),然后通过排队样式使用此常量,例如

wp_enqueue_style(
'main-style',
get_theme_file_uri('assets/css/style.css')
[],
YOUR_THEME_NAME_ASSETS_VERSION
);

4。。使用主题前缀作为样式,以避免名称冲突,例如

wp_enqueue_style(
'your-theme-prefix-main-style',
get_theme_file_uri('assets/css/style.css')
[],
'1.0.0'
);

5。。请确保这些文件位于wp-content/your-theme/assets/css/..目录中。

6。。请确保您具有访问这些文件的足够权限(如果您使用的是基于Linux的Web服务器)

7。。删除此代码<script>alert("its working"); </script>

错误仍然存​​在吗?