WordPress页面教程:静态页(page.php)

一、页面简介

显示静态页的页面(包含各级静态页面)  

 

二、页面参数

  • get_header
  • the_post
  • the_title
  • the_content
  • _e
  • get_the_title
  • comments_template
  • get_footer
  • post_class
  • has_post_thumbnail
  • wp_get_attachment_image_src
  • wp_link_pages
  • bloginfo
  • the_permalink
  • the_title_attribute
  • edit_post_link
  •  

 

 

三、页面案例

(一)、案例1

<?php get_header(); ?>
    <div id="content_wrap">
    <div id="content">
        <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
            <div class="excerpt">
                <div class="context">
				<h2><?php the_title(); ?></h2>
                    <?php the_content('Read more...'); ?>
                </div>
            </div>
            <div class="comments">
			<?php comments_template(); ?>
            </div>
            <?php endwhile; ?>
        <?php endif; ?>
    </div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

 

 

(二)、案例2

<?php get_header(); ?>
<div id="m-container" class="mainContent">
<?php get_sidebar(); ?>
	<div class="blogitem">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content">
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    <h2 class="title"><a class="slow" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><span class="edit"><?php edit_post_link();?></span></h2>
        <ul class="text">

		<?php the_content(); ?>
		
		</ul>
</article>
</div>
<?php endwhile; else: ?>
<?php endif; ?>
	<?php comments_template('', true); ?>
	</div>
</div>
<?php get_footer(); ?>

 

 

(三)、案例3

<?php get_header(); $options = get_neutral_option(); ?>
  <div id="contents" class="clearfix">

   <div id="left_col">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="post">
     <h1 class="post_title" style="margin-bottom:20px;"><?php the_title(); ?></h1>
     <div class="post_content">
      <?php the_content(__('Read more', 'neutral')); ?>
      <?php wp_link_pages(); ?>
     </div>
    </div>

<?php endwhile; else: ?>
    <div class="post">
     <p><?php _e("Sorry, but you are looking for something that isn't here.","neutral"); ?></p>
    </div>
<?php endif; ?>

    <?php if ($options['show_comment']): ?>
    <div id="comments_wrapper">
     <?php if (function_exists('wp_list_comments')) { comments_template('', true); } else { comments_template(); } ?>
    </div>
    <?php endif; ?>

   </div><!-- END #left_col -->

   <?php if($options['layout'] == 'right') { ?>
    <?php get_sidebar(); ?>
   <?php }; ?>

  </div><!-- END #contents -->
<?php get_footer(); ?>

 

 

(四)、案例4

<?php get_header(); ?>
<div id="primary">
<h1 class="sub"><?php the_title(); ?></h1>
<div class="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php if(function_exists('post_class')) : ?><?php post_class(); ?><?php else : ?>class="post post-<?php the_ID(); ?>"<?php endif; ?>>
<?php the_content('<br />[ More .......................................................... ]'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
<?php endwhile; ?>
<?php comments_template('', true); ?>

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

<?php get_sidebar(); ?>
<?php get_footer(); ?>

 

 

(五)、案例5

<?php get_header(); ?>
    <div class="content grid-u-1 grid-u-med-3-4">
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h1 class="content-subhead">
            <a href="<?php bloginfo('url');?>">
                主页
            </a>
            »
            <?php the_title(); ?>
        </h1>
        <article class="post" id="post">
            <header class="post-header">
                <a href="<?php the_permalink(); ?>" class="post-title">
                    <?php the_title(); ?>
                </a>
            </header>
            <div class="post-content">
                <p>
                    <?php the_content(); ?>
                </p>
            </div>
        </article>
		<?php comments_template(); ?>
		<?php endwhile; endif; ?>
        <?php include('/footer-second.php') ?>

 

 

(六)、案例6

<?php get_header(); ?>

	<section id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
					
			<?php while ( have_posts() ) : the_post();

				get_template_part( 'template-parts/content', 'page' );

				comments_template();

			endwhile; ?>
		
		</main><!-- #main -->
	</section><!-- #primary -->
	
	<?php get_sidebar(); ?>

<?php get_footer(); ?>

 

 

 

THE END