Wordpress page.php源代码

时间:2012-12-12 09:40:00

标签: wordpress

<div class="row clearfix">
    <div class="content-wrap ninecol clearfix">
        <div class="content">
           <h1 class="title">Om oss</h1>
           <hr>
           <div class="entry-content">
           <h4>Vilka är Unified Sweden?</h4>
           <p>Unified Sweden är en webbyrå som ständigt strävar </p>
        </div>
    <div>
 </div>

如果我想将其作为模板,以便我可以将其用于其他页面,请使用下面的代码吗?

<div class="content-wrap ninecol clearfix">
    <div class="row clearfix">
        <div class="content">
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                 <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>

                 <?php the_content(); ?>

            <?php endwhile; endif; ?>
        </div>
    <div>
</div>

1 个答案:

答案 0 :(得分:8)

您应该查看Wordpress Template hierarchyPage Templates

您应该创建一个名为page-<something-you-want>.php的文件。打开文件并为其添加模板名称并添加内容。

例如:

<?php
/*
 * Template Name: A Static Page
 */
get_header(); ?>

<whatever content you want to add>

<?php get_footer(); ?>

然后转到Add new Page,在Page Attribute框中,您会看到一个名为Template的下拉菜单。您选择名为A Static Page的模板(或上面定义的其他模板)并发布该页面。这就是全部。

获取内容

要在Wordpress中获取内容,您需要The Loop

 <?php if ( have_posts() ) : while ( have_posts() ) : the_post();       
  the_content(); // displays whatever you wrote in the wordpress editor
  endwhile; endif; //ends the loop
 ?>

回到你的案子:

 <div class="sevencol">
   <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
         <div>
           <?php the_content(); ?>
         </div>
  <?php endwhile; endif; ?>
 </div>
相关问题