Common Template Snippets
written by: Jeff McNearCommon Template Snippets
Featured Images
//Default WordPress
<?php the_post_thumbnail( 'thumbnail' ); ?>// Thumbnail (150 x 150 hard cropped)
<?php the_post_thumbnail( 'medium' ); ?> // Medium resolution (300 x 300 max height 300px)
<?php the_post_thumbnail( 'medium_large' ); ?>// Medium Large (added in WP 4.4) resolution
<?php the_post_thumbnail( 'large' ); ?>// Large resolution (1024 x 1024 max height 1024px)
<?php the_post_thumbnail( 'full' ); ?>// Full resolution (original size uploaded)
//With WooCommerce
<?php the_post_thumbnail( 'shop_thumbnail' ); ?> // Shop thumbnail (180 x 180 hard cropped)
<?php the_post_thumbnail( 'shop_catalog' ); ?> // Shop catalog (300 x 300 hard cropped)
<?php the_post_thumbnail( 'shop_single' ); ?> // Shop single (600 x 600 hard cropped)
Linked Featured Image
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_post_thumbnail( 'medium' ); ?></a>
Linked Page Title
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
Page Title
<?php the_title(); ?>
Published Date
<?php the_date(); ?>
Last Modified Date
<?php
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "<p>Last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo "</p> "; }
?>
Past Author
<?php the_author(); ?>
Post Excerpt
<?php the_excerpt(); ?>
Post Content
<?php the_content(); ?>
Linked Post Categories
<?php the_category(', '); ?>
Unlinked Post Categories
<?php // to display categories without a link
foreach ((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
Linked Post Tages
<?php the_tags(); ?>
Unlinked Post Tags
<?php // to display tags without a link
foreach ((get_the_tags()) as $tag) {
echo $tag->name . ' ';
}
?>
Pulling in an alternative Sidebar
simple version
<?php dynamic_sidebar( 'new_sidebar' ); ?>
conditional version
<?php if ( ! dynamic_sidebar( 'post-sidebar' ) ) : ?>
<?php endif; // end sidebar widget area ?>