Created
July 5, 2020 07:48
-
-
Save ivanteoh/d36c325580ab5a310801650b8e29ca41 to your computer and use it in GitHub Desktop.
WordPress Theme Development 17 - Archives Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customized function for wp_trim_excerpt | |
*/ | |
function customized_trim_excerpt($text) { | |
$raw_excerpt = $text; | |
if ( '' == $text ) { | |
$text = get_the_content(''); | |
$text = strip_shortcodes( $text ); | |
$text = apply_filters('the_content', $text); | |
$text = str_replace(']]>', ']]>', $text); | |
$text = strip_tags($text); | |
$excerpt_length = apply_filters('excerpt_length', 8); | |
$words = explode(' ', $text, $excerpt_length + 1); | |
if (count($words) > $excerpt_length) { | |
array_pop($words); | |
array_push($words, '[...]'); | |
$text = implode(' ', $words); | |
} | |
} | |
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); | |
} | |
remove_filter('get_the_excerpt', 'wp_trim_excerpt'); | |
add_filter('get_the_excerpt', 'customized_trim_excerpt'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package WordPress | |
* @subpackage Your_Theme | |
*/ | |
?> | |
<?php get_header(); ?> | |
<div id="container"> | |
<div id="content"> | |
<!-- archive --> | |
<?php if ( have_posts() ) : ?> | |
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> | |
<?php /* If this is a category archive */ if (is_category()) { ?> | |
<h2><?php _e('Archive for the ‘') ?><?php single_cat_title(); ?> | |
<?php _e('’ Category') ?></h2> | |
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?> | |
<h2><?php _e('Posts Tagged ‘') ?><?php single_tag_title(); ?> | |
<?php _e('’') ?></h2> | |
<?php /* If this is a daily archive */ } elseif (is_day()) { ?> | |
<h2><?php _e('Archive for') ?> <?php the_time('F jS, Y'); ?></h2> | |
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?> | |
<h2><?php _e('Archive for') ?> <?php the_time('F, Y'); ?></h2> | |
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?> | |
<h2><?php _e('Archive for') ?> <?php the_time('Y'); ?></h2> | |
<?php /* If this is an author archive */ } elseif (is_author()) { ?> | |
<h2><?php _e('Author Archive') ?></h2> | |
<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && | |
!empty($_GET['paged'])) { ?> | |
<h2><?php _e('Blog Archives') ?></h2> | |
<?php } ?> | |
<?php while (have_posts()) : ?> | |
<?php the_post(); ?> | |
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> | |
<div class="entry-title"> | |
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php | |
printf( __('Permalink Link to %s'), the_title_attribute('echo=0') ); | |
?>"><?php the_title(); ?></a></h2> | |
</div><!-- .entry-title --> | |
<div class="entry-content"> | |
<?php the_excerpt(); ?> | |
<p><?php wp_link_pages(); ?></p> | |
</div><!-- .entry-content --> | |
<div class="entry-meta"> | |
<p><?php _e('Posted by'); ?> <?php the_author(); ?> @ <?php | |
the_time('F jS, Y'); ?> <?php _e('in'); ?> <?php the_category(','); | |
?> <?php the_tags(__('with '), ', '); ?></p> | |
<p><?php comments_popup_link(__('No Comments »'), | |
__('1 Comment »'), __('% Comments »')); ?> <?php | |
edit_post_link(__('Edit This'), '—'); ?></p> | |
</div><!-- .entry-meta --> | |
</div> | |
<?php comments_template(); ?> | |
<?php endwhile; ?> | |
<p><?php next_posts_link(__('« Older Posts')); ?></p> | |
<p><?php previous_posts_link(__('Newer Posts »')); ?></p> | |
<?php else : ?> | |
<h2><?php _e('Not Found'); ?></h2> | |
<p><?php _e('Sorry, but you are looking for something that isn't here.'); | |
?></p> | |
<?php endif; // END: if ( have_posts() ) ?> | |
</div><!-- #content --> | |
</div><!-- #container --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment