Function Reference: geodir_popular_postview_output
Summary
Generates popular postview HTML.
Global Values
- $post
- (object) (required) The current post object.
- Default: None
- $gridview_columns_widget
- (string) (required) The girdview style of the listings for widget.
- Default: None
- $geodir_is_widget_listing
- (bool) (required) Is this a widget listing?.
- Default: : false
- $gd_session
- (object) (required) GeoDirectory Session object.
- Default: None
Package
GeoDirectory
Parameters
- $args
- (array|string) (required) Display arguments including before_title, after_title, before_widget, and
after_widget.- Default: None
- $instance
- (array|string) (required) The settings for the particular instance of the widget.
- Default: None
Change Log
Since: 1.0.0
1.5.1 View all link fixed for location filter disabled.
1.6.24 View all link should go to search page with near me selected.
Actions
‘geodir_before_view_all_link_in_widget’ [Line: 3878]
‘geodir_after_view_all_link_in_widget’ [Line: 3890]
Filters
‘widget_list_character_count’ [Line: 3729]
‘geodir_template_part-widget-listing-listview’ [Line: 3904]
Source File
geodir_popular_postview_output() is located in geodirectory-functions/general_functions.php [Line: 3622]
Source Code
function geodir_popular_postview_output( $args = '', $instance = '' ) { global $gd_session; // prints the widget extract( $args, EXTR_SKIP ); /** This filter is documented in geodirectory_widgets.php */ $title = empty( $instance['title'] ) ? geodir_ucwords( $instance['category_title'] ) : apply_filters( 'widget_title', __( $instance['title'], 'geodirectory' ) ); /** * Filter the widget post type. * * @since 1.0.0 * * @param string $instance ['post_type'] Post type of listing. */ $post_type = empty( $instance['post_type'] ) ? 'gd_place' : apply_filters( 'widget_post_type', $instance['post_type'] ); /** * Filter the widget's term. * * @since 1.0.0 * * @param string $instance ['category'] Filter by term. Can be any valid term. */ $category = empty( $instance['category'] ) ? '0' : apply_filters( 'widget_category', $instance['category'] ); /** * Filter the widget listings limit. * * @since 1.0.0 * * @param string $instance ['post_number'] Number of listings to display. */ $post_number = empty( $instance['post_number'] ) ? '5' : apply_filters( 'widget_post_number', $instance['post_number'] ); /** * Filter widget's "layout" type. * * @since 1.0.0 * * @param string $instance ['layout'] Widget layout type. */ $layout = empty( $instance['layout'] ) ? 'gridview_onehalf' : apply_filters( 'widget_layout', $instance['layout'] ); /** * Filter widget's "add_location_filter" value. * * @since 1.0.0 * * @param string|bool $instance ['add_location_filter'] Do you want to add location filter? Can be 1 or 0. */ $add_location_filter = empty( $instance['add_location_filter'] ) ? '0' : apply_filters( 'widget_add_location_filter', $instance['add_location_filter'] ); /** * Filter widget's listing width. * * @since 1.0.0 * * @param string $instance ['listing_width'] Listing width. */ $listing_width = empty( $instance['listing_width'] ) ? '' : apply_filters( 'widget_listing_width', $instance['listing_width'] ); /** * Filter widget's "list_sort" type. * * @since 1.0.0 * * @param string $instance ['list_sort'] Listing sort by type. */ $list_sort = empty( $instance['list_sort'] ) ? 'latest' : apply_filters( 'widget_list_sort', $instance['list_sort'] ); /** * Filter widget's "title_tag" type. * * @since 1.6.26 * * @param string $instance ['title_tag'] Listing title tag. */ $title_tag = empty( $instance['title_tag'] ) ? 'h3' : apply_filters( 'widget_title_tag', $instance['title_tag'] ); $use_viewing_post_type = ! empty( $instance['use_viewing_post_type'] ) ? true : false; // set post type to current viewing post type if ( $use_viewing_post_type ) { $current_post_type = geodir_get_current_posttype(); if ( $current_post_type != '' && $current_post_type != $post_type ) { $post_type = $current_post_type; $category = array(); // old post type category will not work for current changed post type } } // replace widget title dynamically $posttype_plural_label = __( get_post_type_plural_label( $post_type ), 'geodirectory' ); $posttype_singular_label = __( get_post_type_singular_label( $post_type ), 'geodirectory' ); $title = str_replace( "%posttype_plural_label%", $posttype_plural_label, $title ); $title = str_replace( "%posttype_singular_label%", $posttype_singular_label, $title ); $categories = $category; if ( ! empty( $category ) && $category[0] != '0' ) { $category_taxonomy = geodir_get_taxonomies( $post_type ); ######### WPML ######### if ( geodir_wpml_is_taxonomy_translated( $category_taxonomy[0] ) ) { $category = gd_lang_object_ids( $category, $category_taxonomy[0] ); } ######### WPML ######### } if ( isset( $instance['character_count'] ) ) { /** * Filter the widget's excerpt character count. * * @since 1.0.0 * * @param int $instance ['character_count'] Excerpt character count. */ $character_count = apply_filters( 'widget_list_character_count', $instance['character_count'] ); } else { $character_count = ''; } if ( empty( $title ) || $title == 'All' ) { $post_type_name = __( get_post_type_plural_label( $post_type ), 'geodirectory' ); $title = !empty( $title ) ? wp_sprintf( __( 'All %s', 'geodirectory' ), $post_type_name ) : $post_type_name; } $location_url = array(); $city = get_query_var( 'gd_city' ); if ( ! empty( $city ) ) { $country = get_query_var( 'gd_country' ); $region = get_query_var( 'gd_region' ); $geodir_show_location_url = get_option( 'geodir_show_location_url' ); if ( $geodir_show_location_url == 'all' ) { if ( $country != '' ) { $location_url[] = $country; } if ( $region != '' ) { $location_url[] = $region; } } else if ( $geodir_show_location_url == 'country_city' ) { if ( $country != '' ) { $location_url[] = $country; } } else if ( $geodir_show_location_url == 'region_city' ) { if ( $region != '' ) { $location_url[] = $region; } } $location_url[] = $city; } $location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true; $location_url = implode( '/', $location_url ); $skip_location = false; if ( ! $add_location_filter && $gd_session->get( 'gd_multi_location' ) ) { $skip_location = true; $gd_session->un_set( 'gd_multi_location' ); } if ( $location_allowed && $add_location_filter && $gd_session->get( 'all_near_me' ) && geodir_is_page( 'location' ) ) { $viewall_url = add_query_arg( array( 'geodir_search' => 1, 'stype' => $post_type, 's' => '', 'snear' => __( 'Near:', 'geodiradvancesearch' ) . ' ' . __( 'Me', 'geodiradvancesearch' ), 'sgeo_lat' => $gd_session->get( 'user_lat' ), 'sgeo_lon' => $gd_session->get( 'user_lon' ) ), geodir_search_page_base_url() ); if ( ! empty( $category ) && !in_array( '0', $category ) ) { $viewall_url = add_query_arg( array( 's' . $post_type . 'category' => $category ), $viewall_url ); } } else { if ( get_option( 'permalink_structure' ) ) { $viewall_url = get_post_type_archive_link( $post_type ); } else { $viewall_url = get_post_type_archive_link( $post_type ); } if ( ! empty( $category ) && $category[0] != '0' ) { global $geodir_add_location_url; $geodir_add_location_url = '0'; if ( $add_location_filter != '0' ) { $geodir_add_location_url = '1'; } $viewall_url = get_term_link( (int) $category[0], $post_type . 'category' ); $geodir_add_location_url = null; } } if ( $skip_location ) { $gd_session->set( 'gd_multi_location', 1 ); } if ( is_wp_error( $viewall_url ) ) { $viewall_url = ''; } $query_args = array( 'posts_per_page' => $post_number, 'is_geodir_loop' => true, 'gd_location' => $add_location_filter ? true : false, 'post_type' => $post_type, 'order_by' => $list_sort ); if ( $character_count ) { $query_args['excerpt_length'] = $character_count; } if ( ! empty( $instance['show_featured_only'] ) ) { $query_args['show_featured_only'] = 1; } if ( ! empty( $instance['show_special_only'] ) ) { $query_args['show_special_only'] = 1; } if ( ! empty( $instance['with_pics_only'] ) ) { $query_args['with_pics_only'] = 0; $query_args['featured_image_only'] = 1; } if ( ! empty( $instance['with_videos_only'] ) ) { $query_args['with_videos_only'] = 1; } $hide_if_empty = ! empty( $instance['hide_if_empty'] ) ? true : false; if ( ! empty( $categories ) && $categories[0] != '0' && !empty( $category_taxonomy ) ) { $tax_query = array( 'taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $category ); $query_args['tax_query'] = array( $tax_query ); } global $gridview_columns_widget, $geodir_is_widget_listing; $widget_listings = geodir_get_widget_listings( $query_args ); if ( $hide_if_empty && empty( $widget_listings ) ) { return; } echo $before_widget; ?>