*/ /** * Retrieves the IDs for images in a gallery. * * Uses Hybrid Media Grabber to get the gallery shortcode. * * @return array List of image IDs from the post gallery. */ function canuck_get_gallery_images() { global $content_width; $args = array( 'post_id' => get_the_ID(), // post ID (assumes within The Loop by default). 'type' => 'gallery', // audio|video. 'before' => '', // HTML before the output. 'after' => '', // HTML after the output. 'split_media' => true, // Splits the media from the post content...KA note...original false. 'width' => $content_width, // Custom width. Defaults to the theme's content width. ); $gallery_string = canuck_media_grabber_gallery( $args ); if ( '' !== $gallery_string ) { $images = array(); $pattern = get_shortcode_regex(); // Note: leave as double quotes, or the preg match will not work. preg_match( "/$pattern/s", $gallery_string, $match );// XSS OK. if ( $match ) { $atts = shortcode_parse_atts( $match[3] ); } else { $atts = false; } if ( false !== $atts && isset( $atts['ids'] ) ) { $images = explode( ',', $atts['ids'] ); } else { $images = false; } } else { $images = false; } if ( false === $images ) { $images = get_posts( array( 'fields' => 'ids', 'numberposts' => 20, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', ) ); } return $images; } /** ======================================================================== * Post Meta * ======================================================================== */ /** * ---------------------- Edit Button -------------------------------------- * Is user is logged in and can edit posts display an edit button. */ function canuck_post_meta_edit() { $user_exists = ( is_user_logged_in() && current_user_can( 'edit_posts' ) ) ? true : false; if ( true === $user_exists ) { edit_post_link( esc_attr__( 'Edit', 'canuck' ), ' ', '' ); } } /** * ---------------------- No Title Button -------------------------------------- * Provide a link to single.php if there is no title. */ function canuck_post_meta_no_title() { $title_exists = ( '' !== get_the_title() ) ? true : false; if ( '' === get_the_title() ) { ?>   "    '; wp_link_pages( 'before=' . $page_text . ':&after=' ); ?>         %2$s', esc_url( get_permalink( get_the_ID() ) ), esc_html__( 'Read More', 'canuck' ) ); } add_filter( 'excerpt_more', 'canuck_excerpt_more' ); /** * Filter the read more link string link to the post. * * @param string $more "Read more" excerpt string. * @return string (Maybe) modified "read more" excerpt string. */ function canuck_modify_read_more_link( $more ) { return sprintf( '
%2$s
', esc_url( get_permalink( get_the_ID() ) ), esc_html__( 'Read More', 'canuck' ) ); } add_filter( 'the_content_more_link', 'canuck_modify_read_more_link' ); /** * Filter the except length to 20 words. * * @param int $length Excerpt length. * @return int (Maybe) modified excerpt length. */ function canuck_custom_excerpt_length( $length ) { if ( is_admin() ) { return $length; } $excerpt_length = get_theme_mod( 'canuck_excerpt_length', 30 ); return $excerpt_length; } add_filter( 'excerpt_length', 'canuck_custom_excerpt_length', 999 ); /** * Excerpt Password - WordPress Codex - display password form in protected posts * * @param string $excerpt is the excerpt of the post. */ function canuck_excerpt_password_form( $excerpt ) { if ( post_password_required() ) { $excerpt = get_the_password_form(); } return $excerpt; } add_filter( 'the_excerpt', 'canuck_excerpt_password_form' ); /** * This function is a helper for post meta in feature-top layouts */ function canuck_post_meta_full() { $post_style = esc_html( get_theme_mod( 'canuck_blog_style', 'top_feature' ) ); if ( is_single() ) { $layout_option = esc_html( get_theme_mod( 'canuck_single_post_layout', 'right_sidebar' ) ); } else { $layout_option = esc_html( get_theme_mod( 'canuck_blog_layout', 'right_sidebar' ) ); } $exclude_timestamp = get_theme_mod( 'canuck_exclude_timestamp', false ); $exclude_author = get_theme_mod( 'canuck_exclude_author', false ); $exclude_category = get_theme_mod( 'canuck_exclude_category', false ); $exclude_tags = get_theme_mod( 'canuck_exclude_tags', false ); if ( is_single() ) { if ( 'fullwidth' === $layout_option ) { canuck_comments_link(); } } else { if ( 'side_feature' === $post_style && 'both_sidebars' !== $layout_option ) { canuck_comments_link(); } } if ( false === $exclude_timestamp ) { canuck_post_meta_timestamp(); } if ( false === $exclude_author ) { canuck_post_meta_author(); } if ( false === $exclude_category ) { canuck_post_meta_category(); } if ( false === $exclude_tags ) { canuck_post_meta_tags(); } if ( is_single() ) { if ( 'fullwidth' !== $layout_option ) { canuck_comments_link(); } } else { if ( 'side_feature' !== $post_style || 'both_sidebars' === $layout_option ) { canuck_comments_link(); } } if ( is_sticky() ) { ?> is_main_query() ) { $query->set( 'cat', $negative_exclude_ids ); } } } add_action( 'pre_get_posts', 'canuck_exclude_category' );