Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added an option to set default view type per directory #1519

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions includes/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ function atbdp_get_listings_orderby_options($sort_by_items)
* @since 4.0.0
*
*/
function atbdp_get_listings_current_view_name($view)
function atbdp_get_listings_current_view_name($view, $directory_type)
{


Expand All @@ -1609,9 +1609,12 @@ function atbdp_get_listings_current_view_name($view)
array_push($allowed_views, 'listings_with_map');
}
if (!in_array($view, $allowed_views)) {
$listing_view = get_directorist_option('default_listing_view');
$listings_settings = !empty($listing_view) ? $listing_view : 'grid';
$view = $listings_settings;
$view = get_term_meta($directory_type, 'default_view_type', true);
if(empty($view)) {
$listing_view = get_directorist_option('default_listing_view');
$listings_settings = !empty($listing_view) ? $listing_view : 'grid';
$view = $listings_settings;
}
}


Expand Down
4 changes: 2 additions & 2 deletions includes/model/Listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function build_search_data( $key, $value ) {

public function prepare_atts_data() {
$defaults = array(
'view' => $this->options['listing_view'],
'view' => !empty(get_term_meta($this->get_current_listing_type(), 'default_view_type', true)) ? get_term_meta($this->get_current_listing_type(), 'default_view_type', true) : $this->options['listing_view'],
'_featured' => 1,
'filterby' => '',
'orderby' => $this->options['order_listing_by'],
Expand Down Expand Up @@ -271,7 +271,7 @@ public function prepare_atts_data() {
$defaults = apply_filters( 'atbdp_all_listings_params', $defaults );
$this->params = shortcode_atts( $defaults, $this->atts );

$this->view = atbdp_get_listings_current_view_name( $this->params['view'] );
$this->view = atbdp_get_listings_current_view_name( $this->params['view'], $this->get_current_listing_type() );
$this->_featured = $this->params['_featured'];
$this->filterby = $this->params['filterby'];
$this->orderby = $this->params['orderby'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,25 @@ public function prepare_settings() {
],
],
] ),
'default_view_type' => [
'label' => __('Default View Type', 'directorist'),
'type' => 'select',
'value' => 'grid',
'options' => [
[
'label' => __('Grid', 'directorist'),
'value' => 'grid',
],
[
'label' => __('List', 'directorist'),
'value' => 'list',
],
[
'label' => __('Map', 'directorist'),
'value' => 'map',
],
],
],

]);

Expand Down Expand Up @@ -4689,6 +4708,17 @@ public function prepare_settings() {
],
],
],
'settings' => [
'label' => __( 'Settings', 'directorist' ),
'sections' => [
'listings_default_view' => [
'title' => __('Default View', 'directorist'),
'fields' => [
'default_view_type'
],
],
],
],
],

],
Expand Down