我正在学习如何从头创建自定义WordPress主题,直到现在一切都工作正常,除了CSS样式表似乎没有正常工作。CSS样式不适用于Wordpress自定义主题
请看看这两个打印屏幕:
1:的index.html
(其中包含HTML的一个基本主题)
2: index.php
(中的index.html转换为index.php文件和删除页眉和页脚部分制作一个WordPress主题后),但我知道问题出在哪里来的。它因为这个JavaScript文件,我试图通过functions.php
在index.php
加载它,但它不起作用。我命名这个文件inline.js
:
$(document).ready(function(){
init_masonry();
});
function init_masonry(){
var $container = $('.item_container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.item',
"gutter": 18,
isFitWidth: true
});
});
}
$(document).ready(function(){
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
这是functions.php
:
<?php
function catalog(){
wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/imagesloaded.pkgd.min.js', array('jquery'));
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/jquery.js', array('jquery'));
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/masonry.pkgd.min.js', array('jquery'));
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/offcanvas.js', array('jquery'));
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/inline.js', array('jquery'));
}
add_action('wp_enqueue_scripts','catalog');
register_nav_menus(array(
'primary' => __('Primary Menu'),
'footer' => __('Footer Menu'),
));
?>
我已经排队了inline.js脚本像其他人一样,但它不工作。我也尝试按Ctrl + F5刷新页面,但没有任何更改。
那么你对这个问题有什么建议吗?
我改变了句柄的名称,但不起作用:( – pouhiocuprai
在你的js文件中,你正在调用[href]在$(document).ready(function(){在$(文档).ready(函数(){{它可能工作,我猜想[href]函数。 –
编辑我的答案。 –