Wordpress page.php source code

2019-08-10 07:57发布

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

if I would want to make this as a template so that I can use it for other pages is the code below right?

<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
1条回答
Melony?
2楼-- · 2019-08-10 08:23

You should have a look at the Wordpress Template hierarchy and Page Templates.

You should create a file called page-<something-you-want>.php. Open the file and add a template name to it and add your content.

For example:

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

<whatever content you want to add>

<?php get_footer(); ?>

Then go to Add new Page, and in the Page Attribute box, you'll see a dropdown called Template. You select the template called A Static Page (or otherwise defined above) and publish the page. That's all.

To get the content

To get the content in Wordpress, you need to 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
 ?>

Getting back to your case:

 <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>
查看更多
登录 后发表回答