strona, post w WP

  • jeśli dana strona ma wyglądać tak jak już opracowany i zakodowany szablon, możemy posłużyć się poniższym kodem by zaciągnąć opracowany kod do pliku php danej strony:

<?php get_template_part('single'); ?>

  • castomowe id, class dla posta:

<a href="<?php the_permalink();?>" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

  • miniaturka wpisu:

<?php the_post_thumbnail(); ?>

<?php if ( has_post_thumbnail() ) { the_post_thumbnail('news_box'); } else { ?><img src="<?php bloginfo('template_url');?>/images/img-blind.png" alt="Webscene"/><?php } ?>

  • pobranie tytułu:


<h1><?php the_title(); ?></h1>


  • pobranie daty:

<?php the_time( get_option( 'date_format' ) ); ?>


<?php the_time('d.m.Y'); ?>


  • pobranie autora:

<a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php echo get_the_author(); ?></a>

  • pobranie kategorii wpisu:


<h2><?php the_category(', ') ?></h2>


  • pobranie treści:

<?php if( '' !== get_post()->post_content ) { ?>
  <div class="page-text">
    <?php the_content(); ?>
  </div>
<?php } ?>

  • pobranie treści z ograniczeniem ilości słów:

w function.php:


function limit_words($string, $word_limit) {
	$words = explode(' ', $string); 
	return implode(' ', array_slice($words, 0, $word_limit)); 
}

w kodzie strony:




<?php echo limit_words(get_the_excerpt(), '15'); echo('<span>...</span>'); ?>


  • korzystanie z post formatów:

w function.php:


add_action( 'after_setup_theme', 'init_post_formats' );
function init_post_formats() {
    add_theme_support( 'post-formats', array( 'image', 'quote' ) );
}

w kodzie strony:


<?php if ( has_post_format( 'quote' )) { ?>
  
<?php } ?>