首页 文章

将HTML模板转换为WordPress主题问题

提问于
浏览
1

我一直在努力将html简单模板转换为WordPress主题,所以我创建了文件夹到xampp - htdocs - wp-content - themes我在这个文件夹中创建了8个文件

footer.php,functions.php,header.php,index.php,page.php sidebar.php,single.php,style.css

In footer file i add this code:-

</div>

                    <?php get_sidebar();?>              
                    <div style="clear: both;">&nbsp;</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>

and in header file i add this code

<!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">

and in index file this code

<?php get_header(); ?>
    test
    <?php get_footer(); ?>

我转到我的管理页面,发现这是一个主题,我活跃了它 . 但我发现它很空洞,我不知道有什么不对 .

3 回答

  • 0

    如果你只得到空白屏幕,那么在大多数情况下,在functions.php中有一些配置错误,你有没有任何代码?

    我不确定它是否能解决您的问题,但尝试在函数中使用wp_enqueue_style()函数,而不是在 Headers 中回显样式 .

    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中,并从 Headers 中删除元素 . bloginfo('stylesheet_url')函数只获取你的主目录url,你没有在我看到的地方调用你的主电源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

  • 1

    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网站并检查

  • 1

    那么你必须在主题文件夹中创建一个新文件夹 . 所以它看起来应该是这样的

    • wp-content

    • 主题

    • 主题名称(比方说布鲁诺)

    • header.php

    • footer.php

    • index.php

    • style.css

    现在在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有关您主题的所有信息

相关问题