WordPress“ wp_register_style被错误地调用”?

时间:2020-03-06 10:48:49

标签: php css templates wordpress-theming

我有一个问题。当我想将此代码放在我的第一个Wordpress模板中时,不起作用。我有一个用于引导的库,还有一个用于我的样式的库。为什么?下面是我的代码。谢谢:D

function load_stylesheets() // funtion name
    {
     wp_register_style('style', get_template_directory_uri() . 'style.css', array(), false, 'all');//style.css
     wp_enqueue_style('style');

     wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), false, 'all');// this is for bootstrap.
     wp_enqueue_style('bootstrap');

}

//添加操作

  add_action('wp_enqueue_scripts', 'load_stylesheets');

//我的front-page.php

<div class="container">


    <div class="row">

            <div class="col">
                Left    
            </div>

            <div class="col">
                Right
            </div>

    </div>

// style.css

body{

background-color: red;
 }

2 个答案:

答案 0 :(得分:0)

也许我做错了,但我无法发表评论,但是我要说要尝试从wp_register_style中取出可选参数,然后使其成为:

wp_register_style('my-style', get_template_directory_uri() . 'style.css');
wp_enqueue_style('my-style');

您可以在此处查看可选参数:https://developer.wordpress.org/reference/functions/wp_register_style/

别忘了将排队的名称更改为您的样式的名称...如果您更改了样式的名称

还要确保由于Bootstrap styesheet位于css目录中,所以style.css是否位于同一目录中,或者style.css是否位于主模板目录中?如果它在主模板目录中,那么很好,但是如果它在css目录中,则需要确保将/css/style.css添加到wp_register_style

答案 1 :(得分:0)

尝试以下方法?:

class TargetCircle(object):
    def __init__(self, posX, posY):
        self.circlePositionX = posX
        self.circlePositionY = posY
        self.radius = 38
        self.theta = 0

    def draw(self, win):
        self.x = int((self.circlePositionX + (self.radius * math.cos(self.theta))))
        self.y = int((self.circlePositionY + (self.radius * math.sin(self.theta))))
        pg.draw.rect(win, gray, (0, self.y, 800, 1))
        pg.draw.rect(win, gray, (self.x, 0, 1, 800))
        pygame.gfxdraw.aacircle(win, self.circlePositionX, self.circlePositionY, self.radius, white)
        pygame.gfxdraw.filled_circle(win, self.x, self.y, 2, white)

确保文件在相应的文件夹中可用。

相关问题