function hocwp_setup_theme_pre_get_posts(WP_Query $query) { if ($query->is_main_query()) { if (is_home()) { $options = hocwp_option_home_setting(); $posts_per_page = absint(hocwp_get_value_by_key($options, 'posts_per_page')); $query->set('posts_per_page', $posts_per_page); } elseif (is_search()) { } if (hocwp_wc_installed()) { if (is_search() || is_archive() && function_exists('is_woocommerce') && is_woocommerce()) { if (!isset($_POST['ppp'])) { $query->set('posts_per_page', hocwp_get_product_posts_per_page()); } } if (is_search()) { $search_cat = hocwp_get_method_value('search_cat', 'request'); if (hocwp_id_number_valid($search_cat)) { $tax_query = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => array($search_cat))); $query->set('tax_query', $tax_query); } } } } return $query; }
{ $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'home_setting'); if (!hocwp_array_has_value($defaults)) { $defaults = array('recent_posts' => 1, 'posts_per_page' => hocwp_get_posts_per_page(), 'pagination' => 1); } return apply_filters('hocwp_option_home_setting_defaults', $defaults); } function hocwp_option_home_setting() { $defaults = hocwp_option_home_setting_defaults(); $options = get_option('hocwp_home_setting'); $options = wp_parse_args($options, $defaults); return apply_filters('hocwp_option_home_setting', $options); } $options = hocwp_option_home_setting(); $posts_per_page = hocwp_get_value_by_key($options, 'posts_per_page'); $pagination = hocwp_get_value_by_key($options, 'pagination'); $recent_posts = hocwp_get_value_by_key($options, 'recent_posts'); global $hocwp_tos_tabs; $parent_slug = 'hocwp_theme_option'; $option = new HOCWP_Option(__('Home Settings', 'hocwp-theme'), 'hocwp_home_setting'); $option->set_parent_slug($parent_slug); $option->set_use_style_and_script(true); $option->set_use_media_upload(true); $option->add_field(array('id' => 'recent_posts', 'title' => __('Recent Posts', 'hocwp-theme'), 'label' => __('Show recent posts on home page?', 'hocwp-theme'), 'value' => $recent_posts, 'field_callback' => 'hocwp_field_input_checkbox')); $option->add_field(array('id' => 'posts_per_page', 'title' => __('Posts Number', 'hocwp-theme'), 'value' => $posts_per_page, 'field_callback' => 'hocwp_field_input_number')); $option->add_field(array('id' => 'pagination', 'title' => __('Pagination', 'hocwp-theme'), 'label' => __('Show pagination on home page?', 'hocwp-theme'), 'value' => $pagination, 'field_callback' => 'hocwp_field_input_checkbox')); $option->add_option_tab($hocwp_tos_tabs); $option->set_page_header_callback('hocwp_theme_option_form_before'); $option->set_page_footer_callback('hocwp_theme_option_form_after');