Created
November 21, 2016 11:07
-
-
Save sarvar/70bedf0c4c8e5137b43c6aab5985929f to your computer and use it in GitHub Desktop.
Wp trim words
This file contains hidden or 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
| <div class="info-box"> | |
| <?php $krogsquery = new WP_Query( array( | |
| 'post_type' => 'post', | |
| 'posts_per_page' => 3 | |
| )); ?> | |
| <h3 class="info-headline">City News</h3> | |
| <?php while($krogsquery->have_posts()) : $krogsquery->the_post(); ?> | |
| <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> | |
| <?php | |
| $trimtitle = get_the_title(); | |
| $shorttitle = wp_trim_words( $trimtitle, $num_words = 4, $more = '… ' ); | |
| echo '<h6 class="info-title">' . '<a href="' . get_permalink() . '">' . $shorttitle . '</a></h6>'; | |
| $trimexcerpt = get_the_excerpt(); | |
| $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… ' ); | |
| echo '<a href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>'; | |
| ?> | |
| </div><!-- post class --> | |
| <?php endwhile; ?> | |
| <?php wp_reset_postdata(); // reset the query ?> | |
| </div><!-- .info-box --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment