'; } } add_action( 'wp_head', 'personaltrainer_pingback_header' ); /** * Remove first post from blog as it is already show via recent post template */ function personaltrainer_alter_home( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $cats = get_theme_mod( 'personaltrainer_front_page_category' ); if ( is_array( $cats ) && ! in_array( '0', $cats ) ) { $query->query_vars['category__in'] = $cats; } } } add_action( 'pre_get_posts', 'personaltrainer_alter_home' ); /** * Function to add Scroll Up icon */ function personaltrainer_scrollup() { $disable_scrollup = get_theme_mod( 'personaltrainer_disable_scrollup' ); if ( $disable_scrollup ) { return; } echo ' ' ; } add_action( 'wp_footer', 'personaltrainer_scrollup', 1 ); if ( ! function_exists( 'personaltrainer_content_nav' ) ) : /** * Display navigation/pagination when applicable * * @since Personal Trainer 0.1 */ function personaltrainer_content_nav() { global $wp_query; // Don't print empty markup in archives if there's only one page. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) { return; } $pagination_type = get_theme_mod( 'personaltrainer_pagination_type', 'default' ); /** * Check if navigation type is Jetpack Infinite Scroll and if it is enabled, else goto default pagination * if it's active then disable pagination */ if ( ( 'infinite-scroll' === $pagination_type ) && class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'infinite-scroll' ) ) { return false; } if ( 'numeric' === $pagination_type && function_exists( 'the_posts_pagination' ) ) { the_posts_pagination( array( 'prev_text' => esc_html__( 'Previous page', 'personal-trainer' ), 'next_text' => esc_html__( 'Next page', 'personal-trainer' ), 'before_page_number' => '' . esc_html__( 'Page', 'personal-trainer' ) . ' ', ) ); } else { the_posts_navigation(); } } endif; // personaltrainer_content_nav /** * Check if a section is enabled or not based on the $value parameter * @param string $value Value of the section that is to be checked * @return boolean return true if section is enabled otherwise false */ function personaltrainer_check_section( $value ) { global $wp_query; // Get Page ID outside Loop $page_id = absint( $wp_query->get_queried_object_id() ); // Front page displays in Reading Settings $page_for_posts = absint( get_option( 'page_for_posts' ) ); return ( 'entire-site' == $value || ( ( is_front_page() || ( is_home() && $page_for_posts !== $page_id ) ) && 'homepage' == $value ) ); } /** * Return the first image in a post. Works inside a loop. * @param [integer] $post_id [Post or page id] * @param [string/array] $size Image size. Either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). * @param [string/array] $attr Query string or array of attributes. * @return [string] image html * * @since Personal Trainer 0.1 */ function personaltrainer_get_first_image( $postID, $size, $attr, $src = false ) { ob_start(); ob_end_clean(); $image = ''; $output = preg_match_all( '//i', get_post_field( 'post_content', $postID ) , $matches ); if( isset( $matches[1][0] ) ) { //Get first image $first_img = $matches[1][0]; if ( $src ) { //Return url of src is true return $first_img; } return ''; } return false; } function personaltrainer_get_theme_layout() { $layout = get_theme_mod( 'personaltrainer_default_layout', 'right-sidebar' ); if ( is_home() || is_archive() || is_search() ) { $layout = get_theme_mod( 'personaltrainer_homepage_archive_layout', 'no-sidebar-full-width' ); } return $layout; } function personaltrainer_get_sidebar_id() { $sidebar = ''; $layout = personaltrainer_get_theme_layout(); if ( 'no-sidebar-full-width' === $layout ) { return $sidebar; } if ( is_active_sidebar( 'sidebar-1' ) ) { $sidebar = 'sidebar-1'; // Primary Sidebar. } return $sidebar; } /** * Featured content posts */ function personaltrainer_get_featured_posts() { $number = get_theme_mod( 'personaltrainer_featured_content_number', 3 ); $post_list = array(); $args = array( 'posts_per_page' => $number, 'post_type' => 'post', 'ignore_sticky_posts' => 1, // ignore sticky posts. ); // Get valid number of posts. $args['post_type'] = 'featured-content'; for ( $i = 1; $i <= $number; $i++ ) { $post_id = get_theme_mod( 'personaltrainer_featured_content_cpt_' . $i ); if ( $post_id ) { $post_list = array_merge( $post_list, array( $post_id ) ); } } $args['post__in'] = $post_list; $args['orderby'] = 'post__in'; $featured_posts = get_posts( $args ); return $featured_posts; }