echo '</div>' . "\n"; } else { $st_['postcount']++; $st_['priority'] = $st_['priority'] == 'odd' ? 'even' : 'odd'; // Post's class $st_['class'] = ''; if ($st_['postcount'] == 1) { $st_['class'] = 'first'; } if ($st_['postcount'] == 4) { $st_['class'] = 'last'; $st_['postcount'] = 0; } // Feat image if (has_post_thumbnail()) { $st_['id'] = get_post_thumbnail_id($post->ID); $st_['thumb'] = wp_get_attachment_image_src($st_['id'], 'project-thumb'); $st_['thumb'] = $st_['thumb'][0]; } else { $st_['thumb'] = get_template_directory_uri() . '/assets/images/placeholder.png'; } // Compose post echo '<div class="posts-featured-c-wrapper c-' . $st_['priority'] . ' ' . $st_['class'] . '">'; // Compose thumb echo '<a href="' . get_permalink() . '" class="post-thumb" ' . (function_exists('st_get_2x') ? st_get_2x($post->ID, 'project-thumb', 'attr') : '') . ' style="background-image: url(' . $st_['thumb'] . ')" data-format="' . $st_['format'] . '"> </a>'; // Other echo '<div class="posts-featured-details-wrapper"><div>' . '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; st_post_meta(false, false, false, 'number', false, true, __('More', 'strictthemes')); echo '</div></div>'; echo '</div>' . "\n"; }
if (has_post_thumbnail()) { $st_['large_image_url'] = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); /*------------------------------------------- on Post page: - sidebar(+) - sidebar(-) -------------------------------------------*/ if (is_single()) { // if sidebar (+) if (!$st_['sidebar_position'] || $st_['sidebar_position'] && $st_['sidebar_position'] != 'none') { echo '<a href="' . $st_['large_image_url'][0] . '" title="' . the_title_attribute('echo=0') . '">' . get_the_post_thumbnail($post->ID, 'post-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'post-image', 'array', 'size-original') : '') . '</a>'; } else { echo '<a href="' . $st_['large_image_url'][0] . '" title="' . the_title_attribute('echo=0') . '">' . get_the_post_thumbnail($post->ID, 'large', function_exists('st_get_2x') ? st_get_2x($post->ID, 'large', 'array', 'size-original') : '') . '</a>'; } } else { // if blog if (!empty($st_['is_blog'])) { // if sidebar (+) if (!$st_['sidebar_position'] || $st_['sidebar_position'] && $st_['sidebar_position'] != 'none') { echo '<a href="' . $st_['large_image_url'][0] . '" title="' . the_title_attribute('echo=0') . '">' . get_the_post_thumbnail($post->ID, 'archive-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'archive-image', 'array', 'size-original') : '') . '</a>'; } else { echo get_the_post_thumbnail($post->ID, 'large', function_exists('st_get_2x') ? st_get_2x($post->ID, 'large') : ''); } } else { echo '<a href="' . $st_['large_image_url'][0] . '" title="' . the_title_attribute('echo=0') . '">' . get_the_post_thumbnail($post->ID, 'archive-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'archive-image', 'array', 'size-original') : '') . '</a>'; } } } ?> </div>
function st_related_posts($qty = 4, $title = '', $h = 'h6', $image_size = 'project-thumb', $class = 'posts-related-wrapper') { global $post; $st_['args'] = array(); $st_['postcount'] = 0; $st_['out'] = ''; // if standard post (for non-CTP) if (get_post_type($post->ID) == 'post') { // by format & category (for non-Standard format) if (get_post_format($post->ID)) { $st_['args'] = array('post_type' => 'post', 'posts_per_page' => $qty, 'order' => 'DESC', 'orderby' => 'rand', 'paged' => 1, 'post_status' => 'publish', 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1, 'tax_query' => array('relation' => 'AND', array('taxonomy' => 'category', 'field' => 'id', 'terms' => wp_get_post_categories($post->ID)), array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-' . get_post_format($post->ID))))); } // get the query $st_query = get_transient('st_related_posts_' . $post->ID); if ($st_query == false) { $st_query = new WP_Query($st_['args']); set_transient('st_related_posts_' . $post->ID, $st_query, 60 * 60 * 24); } // if query result is false -> get a posts (any format) by category if ($st_query->found_posts == 0) { $st_['args'] = array('post_type' => 'post', 'posts_per_page' => $qty, 'order' => 'DESC', 'orderby' => 'rand', 'paged' => 1, 'post_status' => 'publish', 'post__not_in' => array($post->ID), 'ignore_sticky_posts' => 1, 'tax_query' => array('relation' => 'AND', array('taxonomy' => 'category', 'field' => 'id', 'terms' => wp_get_post_categories($post->ID)))); // re-get the query $st_query = new WP_Query($st_['args']); set_transient('st_related_posts_' . $post->ID, $st_query, 60 * 60 * 24); } while ($st_query->have_posts()) { $st_query->the_post(); // Post format $st_['format'] = get_post_format($post->ID) ? get_post_format($post->ID) : 'standard'; $st_['postcount']++; // Feat image if (has_post_thumbnail()) { $st_['id'] = get_post_thumbnail_id($post->ID); $st_['thumb'] = wp_get_attachment_image_src($st_['id'], $image_size); $st_['thumb'] = $st_['thumb'][0]; } else { $st_['thumb'] = get_template_directory_uri() . '/assets/images/placeholder.png'; } // Compose post $st_['out'] .= '<td><div class="posts-related-post-wrapper">'; // Compose thumb $st_['out'] .= '<a href="' . get_permalink() . '" class="post-thumb post-thumb-' . $st_['format'] . '" ' . (function_exists('st_get_2x') ? st_get_2x($post->ID, $image_size, 'attr') : '') . ' style="background-image: url(' . $st_['thumb'] . ')" data-format="' . $st_['format'] . '"> </a>'; // Other $st_['out'] .= '<div class="posts-related-details-wrapper"><div>' . '<h5><a href="' . get_permalink() . '">' . get_the_title() . '</a></h5>'; $st_['out'] .= '</div></div>'; $st_['out'] .= '</div></td>' . "\n"; } wp_reset_query(); // Out if ($st_['out']) { $title = $title ? "\n<" . $h . ">" . $title . "</" . $h . ">\n" : ''; return '<div class="' . $class . ' posts-related-' . $qty . '-wrapper">' . $title . '<table><tbody><tr>' . $st_['out'] . '</tr></tbody></table><div class="clear"><!-- --></div></div>'; } else { return; } } }
// if sidebar (+) if (!$st_['sidebar_position'] || $st_['sidebar_position'] && $st_['sidebar_position'] != 'none') { $st_['feat_img'] = get_the_post_thumbnail($post->ID, 'post-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'post-image', 'array', 'size-original featured-image') : ''); } else { $st_['feat_img'] = get_the_post_thumbnail($post->ID, 'large', function_exists('st_get_2x') ? st_get_2x($post->ID, 'large', 'array', 'size-original featured-image') : ''); } // if modal window (+) if (st_get_post_meta($post->ID, 'lightbox_value', true, '')) { $st_['large_image_url'] = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); echo '<a href="' . $st_['large_image_url'][0] . '" title="' . the_title_attribute('echo=0') . '" >' . $st_['feat_img'] . '</a>'; } else { echo $st_['feat_img']; } } } else { // if blog if (!empty($st_['is_blog'])) { // if sidebar (+) if (!$st_['sidebar_position'] || $st_['sidebar_position'] && $st_['sidebar_position'] != 'none') { echo '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'archive-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'archive-image', 'array', 'size-original featured-image') : '') . '</a>'; } else { echo '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'large', function_exists('st_get_2x') ? st_get_2x($post->ID, 'large', 'array', 'size-original featured-image') : '') . '</a>'; } } else { echo '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'archive-image', function_exists('st_get_2x') ? st_get_2x($post->ID, 'archive-image', 'array', 'size-original featured-image') : '') . '</a>'; } } } ?> </div>