HTML to → WP Conversion

时间:2016-11-01 作者:The WP Intermediate

我从wordpress视频教程开始学习WP主题开发Tutsplus.

一切进展顺利,然后我决定大量练习HTML到WP主题的转换。

我下载了this 免费引导模板。

我能够创造header.php, footer.php, 导航菜单和我从中学到的许多功能here, 但我被击中了index.php 文件创建和content.php 文件创建。

这对我来说是一个小小的障碍→

  <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <header class="intro-header" style="background-image: url(\'img/home-bg.jpg\')">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <div class="site-heading">
                        <h1>Clean Blog</h1>
                        <hr class="small">
                        <span class="subheading">A Clean Blog Theme by Start Bootstrap</span>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-preview">
                    <a href="post.html">
                        <h2 class="post-title">
                            Man must explore, and this is exploration at its greatest
                        </h2>
                        <h3 class="post-subtitle">
                            Problems look mighty small from 150 miles up
                        </h3>
                    </a>
                    <p class="post-meta">Posted by <a href="#">Start Bootstrap</a> on September 24, 2014</p>
                </div>
                <hr>
                <div class="post-preview">
                    <a href="post.html">
                        <h2 class="post-title">
                            I believe every human has a finite number of heartbeats. I don\'t intend to waste any of mine.
                        </h2>
                    </a>
                    <p class="post-meta">Posted by <a href="#">Start Bootstrap</a> on September 18, 2014</p>
                </div>
                <hr>
                <div class="post-preview">
                    <a href="post.html">
                        <h2 class="post-title">
                            Science has not yet mastered prophecy
                        </h2>
                        <h3 class="post-subtitle">
                            We predict too much for the next year and yet far too little for the next ten.
                        </h3>
                    </a>
                    <p class="post-meta">Posted by <a href="#">Start Bootstrap</a> on August 24, 2014</p>
                </div>
                <hr>
                <div class="post-preview">
                    <a href="post.html">
                        <h2 class="post-title">
                            Failure is not an option
                        </h2>
                        <h3 class="post-subtitle">
                            Many say exploration is part of our destiny, but it’s actually our duty to future generations.
                        </h3>
                    </a>
                    <p class="post-meta">Posted by <a href="#">Start Bootstrap</a> on July 8, 2014</p>
                </div>
                <hr>
                <!-- Pager -->
                <ul class="pager">
                    <li class="next">
                        <a href="#">Older Posts &rarr;</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <hr>
事实上,这部分让我很困扰,它是否会进入index.phpcontent.php

  <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <header class="intro-header" style="background-image: url(\'img/home-bg.jpg\')">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <div class="site-heading">
                        <h1>Clean Blog</h1>
                        <hr class="small">
                        <span class="subheading">A Clean Blog Theme by Start Bootstrap</span>
                    </div>
                </div>
            </div>
        </div>
    </header>
My Difficulty →首页显示的帖子标题与HTML, 错在哪里。这是我的index.phpcontent.php 文件→

INDEX.PHP →

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package html2wpsecond
 */

get_header(); ?>

    <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <header class="intro-header" style="background-image: url(\'img/home-bg.jpg\')">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <div class="site-heading">
                        <h1>Clean Blog</h1>
                        <hr class="small">
                        <span class="subheading">A Clean Blog Theme by Start Bootstrap</span>
                    </div>
                </div>
            </div>
        </div>
    </header>


    <!-- Main Content -->
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-preview">
                    <?php If ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <?php get_template_part( \'content\', get_post_format() ); ?>
                    <?php endwhile; ?>

                    <?php else: ?>
                    <?php get_template_part(\'content\',\'none\' ); ?>
                    <?php endif; ?>
                </div>



                <!-- Pager -->
                <ul class="pager">
                    <li class="next">
                        <a href="#">Older Posts &rarr;</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <hr>

<?php
get_sidebar();
get_footer();

CONTENT.PHP →

<?php  

/*
# =======================================
# content.php
#
# The Theme
# =======================================
*/  

?>

<div id=post-<?php the_ID(); ?> <?php post_class(\'post col-md-6\'); ?>>
            <a href="<?php the_permalink( ); ?>" title="<?php the_title_attribute(); ?>" class="post-thumbnail">
            <?php the_post_thumbnail(\'full\', array(\'class\' => \'img-responsive\')); ?>
            </a>


    <div class="post-preview">
        <header>
            <?php
                echo \'<a href="\' . get_the_permalink() . \'"><h3>\' . get_the_title() . \'</h3></a>\';
                blogeto_post_meta();
            ?>
        </header>
            <?php the_content(__(\'Read More\', \'blogeto\')); ?>
    </div>
</div>

1 个回复
SO网友:Patrick B

替换索引中的“主要内容”块。php具有以下特性。这样,您就不需要内容。php文件,可以在索引中查询帖子。php。下一个/上一个后期导航也将起作用。

<!-- Main Content -->
<div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">

                <?php
                // Start the loop.
                while ( have_posts() ) : the_post();
                    ?>
                    <div class="post-preview">
                        <a href="<?php the_permalink(); ?>">
                            <h2 class="post-title">
                                <?php the_title(); ?>
                            </h2>
                            <h3 class="post-subtitle">
                                <?php the_excerpt(); ?>
                            </h3>
                        </a>
                        <p class="post-meta">Posted by <?php the_author(); ?> on <?php the_time(\'jS F Y\') ?></p>
                    </div>
                    <?php

                // End of the loop.
                endwhile;
                ?>


            <!-- Pager -->
            <ul class="pager">
                <li class="next">
                    <?php next_posts_link(\'&laquo; Older Entries\') ?>
                    <?php previous_posts_link(\'Newer Entries &raquo;\') ?>
                </li>
            </ul>
        </div>
    </div>
</div>

相关推荐