' . "\n" . '' . "\n" . '' . "\n" . ''; } add_action('wp_head', 'wk_add_shim'); /** * Add Custom Header BG */ function wk_add_headerbg() { if (get_theme_mod('header_image') != null) : echo ''; endif; } add_action('wp_head', 'wk_add_headerbg'); /** * Extend the default WordPress body classes. * Adds body classes to denote: * 1. Single or multiple authors. * 2. Active widgets in the sidebar to change the layout and spacing. * 3. When avatars are disabled in discussion settings. * @since 1.0.0 * @param array $classes * @return array */ function wk_body_class($classes) { if (!is_multi_author()) { $classes[] = 'single-author'; } if (is_active_sidebar('sidebar-primary') && !is_attachment() && !is_404()) { $classes[] = 'sidebar'; } if (!get_option('show_avatars')) { $classes[] = 'no-avatars'; } if (is_archive() || is_search() || is_home()) { $classes[] = 'list-view'; } if (is_singular() && !is_front_page()) { $classes[] = 'singular'; } return $classes; } add_filter('body_class', 'wk_body_class'); /** * Extend the default WordPress post classes. * Adds a post class to denote: * Non-password protected page with a post thumbnail. * @since 1.0.0 * @param array $classes * @return array */ function wk_post_classes($classes) { if (!post_password_required() && !is_attachment() && has_post_thumbnail()) { $classes[] = 'has-post-thumbnail'; } return $classes; } add_filter('post_class', 'wk_post_classes'); /** * return $images_id array() */ function wk_get_gallery_attachments() { global $post; $post_content = $post->post_content; $ids = array(); preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); if (!empty($ids)) : $images_id = explode(",", $ids[1]); else : $images_id = array(); endif; return $images_id; } /** * Strip shortcode gallery * @param type $content * @return type */ function wk_strip_shortcode_gallery($content) { preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); if (!empty($matches)) { foreach ($matches as $shortcode) { if ('gallery' === $shortcode[2]) { $pos = strpos($content, $shortcode[0]); if ($pos !== false) return substr_replace($content, '', $pos, strlen($shortcode[0])); } } } return $content; } /** * Get attachment meta data * @param type $attachment_id * @return type * @since 1.0.0 */ function wk_get_attachment($attachment_id) { $attachment = get_post($attachment_id); return array( 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink($attachment->ID), 'src' => $attachment->guid, 'title' => $attachment->post_title ); } if (!function_exists('wk_posts_navigation')) : /** * Display navigation to next/previous post when applicable. * @since 1.0.0 */ function wk_posts_navigation() { // Don't print empty markup if there's nowhere to navigate. $previous = ( is_attachment() ) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if (!$next && !$previous) { return; } ?> max_num_pages < 2) { return; } $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1; $pagenum_link = html_entity_decode(get_pagenum_link()); $query_args = array(); $url_parts = explode('?', $pagenum_link); if (isset($url_parts[1])) { wp_parse_str($url_parts[1], $query_args); } $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link); $pagenum_link = trailingslashit($pagenum_link) . '%_%'; $format = $wp_rewrite->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : ''; $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit($wp_rewrite->pagination_base . '/%#%', 'paged') : '?paged=%#%'; // Set up paginated links. $links = paginate_links(array( 'base' => $pagenum_link, 'format' => $format, 'total' => $wp_query->max_num_pages, 'current' => $paged, 'mid_size' => 1, 'add_args' => array_map('urlencode', $query_args), 'prev_text' => __(' Previous', 'wk'), 'next_text' => __('Next ', 'wk'), )); if ($links) : ?> | |
$post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', )); // If there is more than 1 attachment in a gallery... if (count($attachment_ids) > 1) { foreach ($attachment_ids as $attachment_id) { if ($attachment_id == $post->ID) { $next_id = current($attachment_ids); break; } } // get the URL of the next image attachment... if ($next_id) { $next_attachment_url = get_attachment_link($next_id); } // or get the URL of the first image attachment. else { $next_attachment_url = get_attachment_link(array_shift($attachment_ids)); } } printf('%2$s', esc_url($next_attachment_url), wp_get_attachment_image($post->ID, $attachment_size) ); } endif;