这个问题有三个部分。
-
我正在Wordpress中建立一个投资组合网站,并有一些奇怪的链接。例如,在我的about页面上,我的链接是这样的:localhost/AFolder/anotherfolder/index.php/about-me。我进入Permalinks尝试更改链接,但当我将其更改为帖子名称而不是自定义结构时,我的aboutpage上留下了一个断开的链接。我的主页是index.php。我不知道为什么链接引用了index.php。如何解决这个问题?
-
我的设计要求在about页面上使用灰色背景,但它没有显示。除了背景之外,其他一切似乎都在起作用。链接(参考上面的问题)是否因为引用了链接中的index.php文件而干扰了CSS?我主页(index.php)上的大部分背景都是白色的,在我的about页面上看起来也是一样的。也许这两件事有关联。
-
在Wordpress中链接自定义CSS的最佳方式是什么。我已经找到了一种方法,但我不确定这是否是最佳实践:请参阅上面的片段。有没有一个好的插件更适合链接CSS,或者还有其他好的技巧可以做到这一点?
<?php function theme_styles() { wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' ); wp_enqueue_style( 'navbar_css', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'carousel_css', get_template_directory_uri() . '/css/carousel.css' ); } add_action( 'wp_enqueue_scripts', 'theme_styles' ); add_action( 'wp_enqueue_scripts', 'add_custom_styles' ); function add_custom_styles() { wp_enqueue_style( 'about_css', get_template_directory_uri() . '/about-page.css' ); } add_action( 'wp_enqueue_scripts', 'custom_page_css' ); function custom_page_css() { if ( is_page( 'about-me' ) { wp_enqueue_style( 'about_css', get_template_directory_uri() . '/about-page.css' ); } }
您是否尝试过将样式排队
在主题文件夹中的functions.php文件中尝试这些代码。
下面的方法将两种样式(style.css和another_style.css)添加到wp_head();调用action(通常是页面的页眉部分)。
add_action( 'wp_enqueue_scripts', 'add_custom_styles' );
function add_custom_styles() {
wp_enqueue_style('id_of_style', get_template_directory_uri().'/path/to/style.css' );
wp_enqueue_style('id_of_another_style', get_template_directory_uri().'/path/to/another_style.css' );
}
此处按顺序添加样式。样式的排列顺序会影响页面的样式,因为可能会覆盖样式。所以你必须按顺序排列样式。
add_action( 'wp_enqueue_scripts, 'custom_page_css' );
function custom_page_css() {
if ( is_page( 'Custom' ) {
wp_enqueue_style( 'custom-css', get_template_directory_uri().'/path-to/contact.css' );
}
}
此处样式仅添加到自定义页面的标题中
试试这些。记住一件事,你必须知道css文件的顺序。这可能会让我头疼。我也有灰色背景,但订购款式为我解决了问题。
添加脚本也是如此。