Budujemy własny motyw WordPress cz. 2

Witam w drugiej części kursu z budowy motywu WordPress. Dziś pokaże jak dodać do niego kolejne szablony, pliki dające mu kolejne opcje.

Będą to wie kolejno szablony:

  • page.php
  • category.php
  • single.php
  • 404.php

Plik page.php jest podobnie jak single.php stosunkowo prosty

<?php get_header(); ?>

<div class="container">
  <?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  <h1 class="entry-title"><?php the_title(); ?></h1>   
   <div class="entry-content wp-caption">
    <?php the_content(); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'shape' ), 'after' => '</div>' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'shape' ), '<span class="edit-link">', '</span>' ); ?>
  </div><!-- .entry-content -->
  <div class="clear"></div>
</article>
<?php endwhile;  ?>

</div>
<?php get_footer(); ?>

Dla uproszczenia pominęłam jeszcze opcję komentowania postów (single.php).

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

<div class="container">
  <div class="entry-content">

   <h1 class="entry-title"><?php the_title(); ?></h1>

  <div class="imgpost four columns"><?php the_post_thumbnail(); ?></div>
    <?php the_content( __( 'Continue reading <span class="meta-nav">&amp;raquo;</span>', 'your-theme' ) ); ?>
     <div class="eight columns">
       <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&amp;after=</div>') ?>
     </div>
   </div><!-- .entry-content -->
 </div>
<?php endwhile; ?>
<?php get_footer(); ?>

Jak widać oba szablony mają podobną budowę. Trzeba przy tym pamiętać że w bardziej rozbudowanych motywach może być więcej jak jeden szablon strony. O tym jak go utworzyć pisałam wcześniej w innym poście.

Na pewno inną budowę posiada szablon kategorii czyli category.php

<?php get_header(); ?>
<div class="container">
<h1 class="entry-title"><?php _e( '', 'sss' ) ?> <?php single_cat_title() ?></h1>

<?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( '', '<div class="archive-meta">' . $categorydesc . '</div>' ); ?>
<?php if ( $cats_meow = cats_meow(', ') ) : // Returns categories other than the one queried ?>
<?php endif ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="entry-content">
<article id="post-<?php the_ID(); ?>" class="oferty">
<div class="title">
<h3 class="entry-title"> <?php echo get_the_date( 'Y-m-d' ); ?> | <?php the_title(); ?></h3></div>
<div class="four columns"><?php the_post_thumbnail(); ?></div> 
<div class="eight columns">
<?php the_content( __( 'Continue reading <span class="meta-nav">&amp;raquo;</span>', 'your-theme' ) ); ?></div>

<div class="clear"></div>
</article> 
</div>
<?php endwhile; ?>
<!-- post navigation -->
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>
</div>
<?php get_footer(); ?>

Kwestia budowy strony 404.php w dużym stopniu jest umowna i może wyglądać np. tak.

<?php get_header(); ?>

<div class="container">

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php _e( 'Not Found', 'your-theme' ); ?></h1>
<div class="entry-content wp-caption">

<h2><?php _e( 'This is somewhat embarrassing, isn&rsquo;t it?', 'your-theme' ); ?></h2>
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'your-theme' ); ?></p>
<?php get_search_form(); ?>

</div><!-- .entry-content -->
<div class="clear"></div>
</article>


</div>
<?php get_footer(); ?>

PRZECZYTAJ

Dodatkowe tagi:
skórka WordPress
nowy szablon, motyw dla strony
kurs budowy wyglądu strony
własna szata graficzna