Category: Code

Custom Post Pagination not working

Custom post query

  1. post type download
  2. post content style content-item.php
  3. post pagination function st_posts_pagination
 <?php
 global $wp_query;
 query_posts( array('post_type' => array( 'download' ), 'paged'=>$paged )
 );?>

 <?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
 <?php get_template_part('content', 'item'); ?>
 <?php endwhile; ?>
 <?php ?>
 <div class="col-md-12">
 <div class="page-link text-center">
 <?php st_posts_pagination(); ?>
 </div>
 </div>

 <?php endif; ?>

Continue Reading

Add class on categories widget for post counter styling

function rm_categories_post_count_filter ($cat_post_count) {
    $cat_post_count = str_replace('(', '<span class="post_count pull-right"> (', $cat_post_count);
    $cat_post_count = str_replace(')', ' )</span>', $cat_post_count);
    return $cat_post_count;
}
add_filter('wp_list_categories','rm_categories_post_count_filter');

Limiting WP Post content and adding conditional Read More button

Content limit 110 words.

<?php $trimexcerpt = get_the_content();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 110, $more = ' [...]' );
echo "<p>" .$shortexcerpt. "</p>";
?>

After 110 words show “Read More”

<?php
$count = str_word_count($shortexcerpt);

if($count >= 110){ ?>
    <a href="<?php the_permalink(); ?>" class="st-more-link text-center
 text-uppercase"><span><?php _e('Read More', 'cherry') ?></span></a>
<?php } ?>