/** * * Get the content for posts * */ public function getPostContent($params = array()) { $content = ''; // Initiate shortcode query builder class $shortcodeQuery = new Runway_ShortcodeQueryBuilder(); $wp_query_args = $shortcodeQuery->getQueryParams($params); if (!$wp_query_args) { return; } // Make sure we get all queried items $wp_query_args['posts_per_page'] = -1; // make new query based on shortcode $the_query = new WP_Query($wp_query_args); if ($the_query->have_posts()) { // Get posts and content // ------------------------------------------------------------------ // Loop through the results and print each. while ($the_query->have_posts()) { $the_query->the_post(); $linkTitle = esc_attr(sprintf(__('Permalink to %s', 'framework'), the_title_attribute('echo=0'))); $excerptLength = isset($params['excerpt_length']) ? $params['excerpt_length'] : 20; $id = get_the_ID(); $content[$id] = ''; // Thumbnail image if (has_post_thumbnail()) { // Get the image data $image['post_id'] = $id; if (isset($params['image_size'])) { $image['image_size'] = $params['image_size']; } // Retrieve the resized image $thumbnail = $this->getResizedImage($image); // see if we have any content after the image $hasContent = ''; if (isset($params['hide_title']) && $params['hide_title'] == 'true' && (!isset($params['post_excerpts']) || empty($params['post_excerpts']))) { $hasContent = 'no-content'; } // Build the image container $content[$id] .= '<div class="featured-image ' . $hasContent . '" data-image="' . esc_url($thumbnail['large_image']) . '">'; $content[$id] .= '<a href="' . get_permalink() . '" class="styled-image ' . get_post_format() . '" title="' . $linkTitle . '" rel="bookmark">' . $thumbnail['full_image_tag'] . '</a>'; $content[$id] .= '</div>'; } // Post title if (!isset($params['hide_title']) || $params['hide_title'] !== 'true') { $content[$id] .= '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . $linkTitle . '">' . get_the_title() . '</a></h2>'; } // Post content if (isset($params['post_excerpts']) && !empty($params['post_excerpts'])) { $content[$id] .= '<div class="entry-content"><p>' . customExcerpt(get_the_excerpt(), $excerptLength) . '</p></div>'; } } } // Clean up unset($the_query); unset($wp_query_args); wp_reset_postdata(); return $content; }
function custom_wp_query($args = null, $content = null) { global $custom_query, $paged; // Initiate shortcode query builder class $shortcodeQuery = new Runway_ShortcodeQueryBuilder(); $wp_query_args = $shortcodeQuery->getQueryParams($args); if (!$wp_query_args) { return; } // Force a default template if (!isset($wp_query_args['template'])) { $wp_query_args['template'] = "blog"; /** * TODO: This would be a great place to use WP template functions to test for the * existance of a template file before setting a default or using the one specified. */ } //-- workaround for shortcode paging not working on static home page --// $paged = $paged ? $paged : get_query_var('page'); if ($paged < 1) { $paged = 1; } $wp_query_args['paged'] = $paged; //-- end of paging workaround --// // make new query based on shortcode $custom_query = new WP_Query($wp_query_args); // make html ob_start(); get_template_part('templates/' . $wp_query_args['template']); $html = ob_get_clean(); unset($custom_query); unset($wp_query_args); wp_reset_postdata(); return $html; }