WordPress页面.php源代码


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

您应该查看Wordpress模板层次结构和页面模板。

您应该创建一个名为 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中获取内容,您需要循环

 <?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>

最新更新