Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Adds Schema Event Posts to Gardening Classes Page */
- function wpb_postsbycategory() {
- /* the query */
- $the_query = new WP_Query( array( 'post_type' => 'schema_event_post', 'posts_per_page' => 8 ) );
- /* The Loop */
- if ( $the_query->have_posts() ) {
- $string .= '<ul class="postsbycategory widget_recent_entries">';
- while ( $the_query->have_posts() ) {
- $the_query->the_post();
- if ( has_post_thumbnail() ) {
- $string .= '<li>';
- $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 150, 150) ) . get_the_title() .'</a><br /> '. get_the_excerpt() .'</li><br />';
- } else {
- /* if no featured image is found */
- $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a><br /> '. get_the_excerpt() .'</li><br />';
- }
- }
- } else {
- /* no posts found */
- }
- $string .= '</ul>';
- return $string;
- /* Restore original Post Data */
- wp_reset_postdata();
- }
- /* Add a shortcode */
- add_shortcode('categoryposts', 'wpb_postsbycategory');
- /* Enable shortcodes in text widgets */
- add_filter('widget_text', 'do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement