Wordpress page.php源代码

Vic*_*cky 1 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>
Run Code Online (Sandbox Code Playgroud)

如果我想把它作为一个模板,以便我可以将它用于其他页面是下面的代码吗?

<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>
Run Code Online (Sandbox Code Playgroud)

RRi*_*esh 8

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

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

例如:

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

<whatever content you want to add>

<?php get_footer(); ?>
Run Code Online (Sandbox Code Playgroud)

然后去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
 ?>
Run Code Online (Sandbox Code Playgroud)

回到你的案子:

 <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>
Run Code Online (Sandbox Code Playgroud)