max_num_pages; if ( $total_pages > 1 ) { $current_page = max( 1, get_query_var( 'paged' ) ); if ( ! is_search() ) { echo paginate_links( array( 'current' => $current_page, 'total' => $total_pages, ) ); } else { echo paginate_links( array( 'base' => get_pagenum_link( 1 ) . '%_%', 'format' => ( ( get_option( 'permalink_structure' ) && ! $wp_query->is_search ) || ( is_home() && get_option( 'show_on_front' ) !== 'page' && ! get_option( 'page_on_front' ) ) ) ? '?paged=%#%' : '&paged=%#%', // %#% will be replaced with page number 'current' => $current_page, 'total' => $total_pages, ) ); } } } /* * Check if the curernt post (or page) has a focus area that needs to be rendered * @return Boolean */ function thrive_check_top_focus_area() { if ( is_home() || is_404() ) { return false; } global $post; if ( ! $post || ! isset( $post->post_type ) ) { return false; } if ( $post->post_type == TT_APPR_POST_TYPE_LESSON || $post->post_type == TT_APPR_POST_TYPE_PAGE ) { $post->post_type = "post"; } if ( $post->post_type == "post" ) { return _thrive_check_top_focus_area_post( $post ); } else { return _thrive_check_top_focus_area_page( $post ); } } function thrive_check_blog_focus_area( $position ) { if ( ! is_home() ) { return false; } $query = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_location&meta_value=between_posts&order=ASC" ); $focus_areas = $query->get_posts(); foreach ( $focus_areas as $temp_focus ) { $post_custom_atr = get_post_custom( $temp_focus->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] ) && $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] == $position ) { return true; } } return false; } /* * Check if the curernt post (or page) has a focus area that needs to be rendered * @return Boolean */ function thrive_check_bottom_focus_area() { if ( is_home() || is_404() ) { return false; } global $post; if ( ! $post || ! isset( $post->post_type ) ) { return false; } if ( $post->post_type == "post" ) { return _thrive_check_top_focus_area_post( $post, "bottom" ); } else { return _thrive_check_top_focus_area_page( $post, "bottom" ); } } /* * Helper function used to check if the curernt post has a focus area that needs to be rendered * @param Post object * @return Boolean */ function _thrive_check_top_focus_area_post( $post, $position = "top" ) { $custom_fields = get_post_custom( $post->ID ); if ( $position == "top" ) { if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "post" ) { return true; } if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $custom_fields['_thrive_meta_post_focus_area_top'][0] == "hide" && $post->post_type == "post" ) { return false; } } else { if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) { return true; } if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $custom_fields['_thrive_meta_post_focus_area_bottom'][0] == "hide" && $post->post_type == "post" ) { return false; } } $post_categories = wp_get_post_categories( $post->ID ); $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" ); foreach ( $query1->get_posts() as $p ) { //check for the top display option $post_custom_atr = get_post_custom( $p->ID ); $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] ); if ( ! is_array( $focus_cats ) ) { $focus_cats = array(); } if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position && ( $post_custom_atr['_thrive_meta_focus_display_is_default'][0] == 1 || count( array_intersect( $post_categories, $focus_cats ) ) > 0 ) ) { return true; } } return false; } /* * Helper function used to check if the curernt page has a focus area that needs to be rendered * @param Post object * @return Boolean */ function _thrive_check_top_focus_area_page( $post, $position = "top" ) { $custom_fields = get_post_custom( $post->ID ); if ( $position == "top" ) { if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "page" ) { return true; } if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $custom_fields['_thrive_meta_post_focus_area_top'][0] == "hide" && $post->post_type == "page" ) { return false; } } else { if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) { return true; } if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $custom_fields['_thrive_meta_post_focus_area_bottom'][0] == "hide" && $post->post_type == "page" ) { return false; } } $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" ); $post_categories = wp_get_post_categories( $post->ID ); foreach ( $query2->get_posts() as $p ) { $post_custom_atr = get_post_custom( $p->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_categories'] ) && $post_custom_atr['_thrive_meta_focus_display_categories'][0] ) { $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] ); } else { $focus_cats = array(); } if ( ! is_array( $focus_cats ) ) { $focus_cats = array(); } if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position ) { return true; } } return false; } /* * Renders the top focus area */ function thrive_render_top_focus_area( $position = "top", $place = null, $return_content = false ) { global $post; if ( empty( $post ) ) { return; } $current_post = $post; $page_focus = null; $post_focus = null; $current_focus = null; $current_focus_attrs = null; $custom_fields = get_post_custom( $post->ID ); if ( $position == "top" ) { if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "post" ) { $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ); } if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "page" ) { $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ); } } else { if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) { $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ); } if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) { $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ); } } if ( ! $post_focus ) { $post_categories = wp_get_post_categories( $post->ID ); $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" ); foreach ( $query1->get_posts() as $p ) { $post_custom_atr = get_post_custom( $p->ID ); $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] ); if ( ! is_array( $focus_cats ) ) { $focus_cats = array(); } if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position && ( $post_custom_atr['_thrive_meta_focus_display_is_default'][0] == 1 || count( array_intersect( $post_categories, $focus_cats ) ) > 0 ) ) { $post_focus = $p; } } } if ( ! $page_focus ) { $post_categories = wp_get_post_categories( $post->ID ); //get the focus area for the posts and for the pages, if any is set $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" ); foreach ( $query2->get_posts() as $p ) { $post_custom_atr = get_post_custom( $p->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_categories'] ) && $post_custom_atr['_thrive_meta_focus_display_categories'][0] ) { $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] ); } else { $focus_cats = array(); } if ( ! is_array( $focus_cats ) ) { $focus_cats = array(); } if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position ) { $page_focus = $p; } } } if ( $current_post->post_type == "post" ) { if ( $post_focus ) { $current_focus = $post_focus; } } if ( $post->post_type == "page" ) { if ( $page_focus ) { $current_focus = $page_focus; } } if ( $position == "between_posts" ) { $query3 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_location&meta_value=between_posts&order=ASC&posts_per_page=-1" ); $focus_areas = $query3->get_posts(); foreach ( $focus_areas as $temp_focus ) { $post_custom_atr = get_post_custom( $temp_focus->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] ) && $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] == $place ) { $current_focus = $temp_focus; } } } if ( $place == "blog" || $place == "archive" ) { if ( $place == "blog" ) { $query4 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_page_blog&meta_value=blog&order=ASC&posts_per_page=-1" ); } elseif ( $place == "archive" ) { $query4 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_page_archive&meta_value=archive&order=ASC&posts_per_page=-1" ); } $focus_areas = $query4->get_posts(); foreach ( $focus_areas as $focus_area ) { $post_custom_atr = get_post_custom( $focus_area->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position ) { $current_focus = $focus_area; } } } if ( ! $current_focus ) { return; } $current_attrs = get_post_custom( $current_focus->ID ); if ( $return_content ) { return ( isset( $current_attrs['_thrive_meta_focus_subheading_text'][0] ) ) ? $current_attrs['_thrive_meta_focus_subheading_text'][0] : ''; } if ( ! $current_attrs || ! isset( $current_attrs['_thrive_meta_focus_template'] ) || ! isset( $current_attrs['_thrive_meta_focus_template'][0] ) ) { return; } if ( isset( $current_attrs['_thrive_meta_focus_optin'] ) && isset( $current_attrs['_thrive_meta_focus_optin'][0] ) ) { $optin_id = (int) $current_attrs['_thrive_meta_focus_optin'][0]; //form action $optinFormAction = get_post_meta( $optin_id, '_thrive_meta_optin_form_action', true ); //form method $optinFormMethod = get_post_meta( $optin_id, '_thrive_meta_optin_form_method', true ); $optinFormMethod = strtolower( $optinFormMethod ); $optinFormMethod = $optinFormMethod === 'post' || $optinFormMethod === 'get' ? $optinFormMethod : 'post'; //form hidden inputs $optinHiddenInputs = get_post_meta( $optin_id, '_thrive_meta_optin_hidden_inputs', true ); //form fields $optinFieldsJson = get_post_meta( $optin_id, '_thrive_meta_optin_fields_array', true ); $optinFieldsArray = json_decode( $optinFieldsJson, true ); //form not visible inputs $optinNotVisibleInputs = get_post_meta( $optin_id, '_thrive_meta_optin_not_visible_inputs', true ); } else { $optinFieldsArray = array(); $optinFormAction = ""; $optinHiddenInputs = ""; } $value_focus_template = strtolower( $current_attrs['_thrive_meta_focus_template'][0] ); //TODO - refactorize this if ( $value_focus_template == "template3" || $value_focus_template == "template6" ) { $value_focus_template = "template1"; } $template_path = get_template_directory() . "/focusareas/" . $value_focus_template . ".php"; if ( $position != "top" ) { //echo $template_path; die; } if ( ! empty( $_GET['tve'] ) ) { return; } require $template_path; } /* * Renders the bottom focus area */ function thrive_render_bottom_focus_area() { global $post; $current_post = $post; $page_focus = null; $post_focus = null; $current_focus = null; $custom_fields = get_post_custom( $post->ID ); if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) { $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ); } if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) { $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ); } //get the focus area for the posts and for the pages, if any is set $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" ); foreach ( $query1->get_posts() as $p ) { $post_custom_atr = get_post_custom( $p->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == "bottom" ) { $post_focus = $p; } } //get the focus area for the posts and for the pages, if any is set $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" ); foreach ( $query2->get_posts() as $p ) { $post_custom_atr = get_post_custom( $p->ID ); if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == "bottom" ) { $page_focus = $p; } } if ( $current_post->post_type == "post" ) { if ( $post_focus ) { $current_focus = $post_focus; } } if ( $post->post_type == "page" ) { if ( $page_focus ) { $current_focus = $page_focus; } } if ( ! $current_focus ) { return; } $current_attrs = get_post_custom( $current_focus->ID ); if ( ! $current_attrs || ! isset( $current_attrs['_thrive_meta_focus_template'] ) || ! isset( $current_attrs['_thrive_meta_focus_template'][0] ) ) { return; } $template_path = get_template_directory() . "/focusareas/" . strtolower( $current_attrs['_thrive_meta_focus_template'][0] ) . "_bottom.php"; require_once $template_path; } /* * Changes the page menu markup in order to render it accordingly to the theme's markup * @param string $page_markup The menu markup * @return string The new markup */ function thrive_custom_page_menu( $page_markup ) { preg_match( '/^
/i', $page_markup, $matches ); $divclass = $matches[1]; $toreplace = array( '
', '
' ); $new_markup = str_replace( $toreplace, '', $page_markup ); $new_markup = preg_replace( '/^