Wordpress page.php 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13836830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:06:28  来源:igfitidea点击:

Wordpress page.php source code

wordpress

提问by Vicky Picky

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

回答by RRikesh

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

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

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.

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

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 Attributebox, 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.

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

To get the content

获取内容

To get the content in Wordpress, you need to The Loop

要获取 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
 ?>

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>