[英]Convert a HTML Template into a WordPress Theme issue
我一直在将html简单模板转换为WordPress主题,因此我将文件夹创建为xampp-htdocs-wp-content-主题,并在此文件夹中创建8个文件
footer.php,functions.php,header.php,index.php,page.php sidebar.php,single.php,style.css
在页脚文件中,我添加以下代码:-
</div>
<?php get_sidebar();?>
<div style="clear: both;"> </div>
</div>
</div>
</div>
<!-- end #page -->
</div>
<div id="footer">
<p>Copyright (c) 2013 Sitename.com. All rights reserved. | Photos by <a href="http://fotogrph.com/">Fotogrph</a> | Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p>
</div>
<!-- end #footer -->
</body>
</html>
并在头文件中添加此代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php bloginfo('title'); ?></title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" media="screen" />
<?php wp_head(); ?>
</head>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1><a href="#"><?php bloginfo('name'); ?></a></h1>
<p><?php bloginfo('description'); ?></p>
</div>
</div>
</div>
<!-- end #header -->
<div id="menu">
<?php wp_nav_menu(); ?>
</div>
<!-- end #menu -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="content">
并在索引文件中此代码
<?php get_header(); ?>
test
<?php get_footer(); ?>
我进入管理页面,在此找到它作为主题,并激活了它。 但是我发现它很空,我不知道出了什么问题。
WordPress主题至少需要两个文件才能工作,因此首先通过在主题文件夹中仅包含两个文件来检查主题
wp-content/themes/mytheme/
style.css
index.php
将这些行添加到您的style.css文件中
/*
Theme Name: My theme
Version: 1.0
*/
并将这些行添加到index.php文件中
this is theme testing
然后运行您的wordpress网站并检查
如果只有空白屏幕,则在大多数情况下,functions.php中存在一些配置错误,您那里是否有任何代码?
我不确定是否能解决您的问题,但是请尝试在函数中使用wp_enqueue_style()函数,而不是在标头中回显您的样式。
function theme_slug_enqueue( ){
wp_enqueue_style( 'open-sans', http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' );
wp_enqueue_style( 'main-style', get_stylesheet_directory_uri() . 'style.css' );
}
将其放在您的functions.php中,并从标题中删除元素。 bloginfo('stylesheet_url')函数仅获取您的主目录url,据我所知,您没有在任何地方调用mains style.css。 如果您不想使用wordpress标准入队功能,至少尝试更改
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" media="screen" />
至:
<link href="<?php bloginfo('stylesheet_url') . 'style.css'; ?>" rel="stylesheet" type="text/css" media="screen" />
参考: https ://codex.wordpress.org/Function_Reference/wp_enqueue_style
好了,您必须在主题文件夹中创建一个新文件夹。 所以它应该看起来像这样
WP-内容
主题名称(让我们说bruno)
现在在style.css中,添加这些注释很重要。
/*
Theme Name: Bruno theme
Theme URI: Your site
Author: Your name
Author URI: http://yoursite.org/
Description: Some description
Version: 1.0
*/
这些评论将告诉wordpress有关您主题的所有信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.