Ejemplo n.º 1
0
function get_categories_inherited_properties($cats)
{
    $cat_options = array();
    if ($cats) {
        foreach ($cats as $cat) {
            $new_options = get_category_inherited_properties($cat['term_id']);
            foreach ($new_options as $k => $v) {
                if (!empty($v) && !is_inherit_option($v) && (!isset($cat_options[$k]) || empty($cat_options[$k]) || is_inherit_option($cat_options[$k]))) {
                    $cat_options[$k] = $v;
                }
            }
        }
    }
    return $cat_options;
}
Ejemplo n.º 2
0
 function themerex_posts_per_page_selector($query)
 {
     if (is_admin() || !$query->is_main_query()) {
         return;
     }
     $orderby_set = true;
     $orderby = get_theme_option('blog_sort');
     $order = get_theme_option('blog_order');
     // Set posts per page
     $ppp = (int) get_theme_option('posts_per_page');
     $ppp2 = 0;
     if ($query->is_category()) {
         $cat = (int) $query->get('cat');
         if (empty($cat)) {
             $cat = $query->get('category_name');
         }
         if (!empty($cat)) {
             //$ppp2 = (int) get_category_inherited_property($cat, 'posts_per_page', 0);
             $cat_options = get_category_inherited_properties($cat);
             if (isset($cat_options['posts_per_page']) && !empty($cat_options['posts_per_page']) && !is_inherit_option($cat_options['posts_per_page'])) {
                 $ppp2 = (int) $cat_options['posts_per_page'];
             }
             if (isset($cat_options['blog_sort']) && !empty($cat_options['blog_sort']) && !is_inherit_option($cat_options['blog_sort'])) {
                 $orderby = $cat_options['blog_sort'];
             }
             if (isset($cat_options['blog_order']) && !empty($cat_options['blog_order']) && !is_inherit_option($cat_options['blog_order'])) {
                 $order = $cat_options['blog_order'];
             }
         }
     } else {
         if ($query->get('post_type') == 'product' || $query->get('product_cat') != '' || $query->get('product_tag') != '') {
             $orderby_set = false;
             $page_id = get_option('woocommerce_shop_page_id');
         } else {
             if ($query->is_archive()) {
                 $page_id = getTemplatePageId('archive');
             } else {
                 if ($query->is_search()) {
                     $page_id = getTemplatePageId('search');
                     if (get_theme_option('use_ajax_search') == 'yes') {
                         $show_types = get_theme_option('ajax_search_types');
                         if (!empty($show_types)) {
                             $query->set('post_type', explode(',', $show_types));
                         }
                     }
                 } else {
                     if ($query->is_posts_page == 1) {
                         $page_id = isset($query->queried_object_id) ? $query->queried_object_id : getTemplatePageId('blog');
                     } else {
                         $page_id = 0;
                     }
                 }
             }
         }
         if ($page_id > 0) {
             $post_options = get_post_meta($page_id, 'post_custom_options', true);
             if (isset($post_options['posts_per_page']) && !empty($post_options['posts_per_page']) && !is_inherit_option($post_options['posts_per_page'])) {
                 $ppp2 = (int) $post_options['posts_per_page'];
             }
             if ($orderby_set) {
                 if (isset($post_options['blog_sort']) && !empty($post_options['blog_sort']) && !is_inherit_option($post_options['blog_sort'])) {
                     $orderby = $post_options['blog_sort'];
                 }
                 if (isset($post_options['blog_order']) && !empty($post_options['blog_order']) && !is_inherit_option($post_options['blog_order'])) {
                     $order = $post_options['blog_order'];
                 }
             }
         }
     }
     if ($ppp2 > 0) {
         $ppp = $ppp2;
     }
     if ($ppp > 0) {
         $query->set('posts_per_page', $ppp);
     }
     if ($orderby_set) {
         addSortOrderInQuery($query, $orderby, $order);
     }
     // Exclude categories
     $ex = get_theme_option('exclude_cats');
     if (!empty($ex)) {
         $query->set('category__not_in', explode(',', $ex));
     }
 }
Ejemplo n.º 3
0
function load_custom_options()
{
    // Theme custom settings from current post and category
    global $THEMEREX_cat_options, $THEMEREX_post_options, $THEMEREX_custom_options, $THEMEREX_shop_options, $wp_query;
    // Current post & category custom options
    $THEMEREX_post_options = $THEMEREX_cat_options = $THEMEREX_custom_options = $THEMEREX_shop_options = array();
    if (is_woocommerce_page() && ($page_id = get_option('woocommerce_shop_page_id')) > 0) {
        $THEMEREX_shop_options = get_post_meta($page_id, 'post_custom_options', true);
    }
    if (is_category()) {
        $cat = (int) get_query_var('cat');
        if (empty($cat)) {
            $cat = get_query_var('category_name');
        }
        $THEMEREX_cat_options = get_category_inherited_properties($cat);
    } else {
        if ((is_day() || is_month() || is_year()) && ($page_id = getTemplatePageId('archive')) > 0) {
            $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
        } else {
            if (is_search() && ($page_id = getTemplatePageId('search')) > 0) {
                $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
            } else {
                if (is_404() && ($page_id = getTemplatePageId('404')) > 0) {
                    $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
                } else {
                    if (function_exists('is_bbpress') && is_bbpress() && ($page_id = getTemplatePageId('bbpress')) > 0) {
                        $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
                    } else {
                        if (function_exists('is_buddypress') && is_buddypress() && ($page_id = getTemplatePageId('buddypress')) > 0) {
                            $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
                        } else {
                            if (is_attachment() && ($page_id = getTemplatePageId('attachment')) > 0) {
                                $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
                            } else {
                                if (is_single() || is_page() || is_singular() || $wp_query->is_posts_page == 1) {
                                    // Current post custom options
                                    $page_id = is_single() || is_page() ? get_the_ID() : (isset($wp_query->queried_object_id) ? $wp_query->queried_object_id : getTemplatePageId('blog'));
                                    $THEMEREX_post_options = get_post_meta($page_id, 'post_custom_options', true);
                                    $THEMEREX_cat_options = get_categories_inherited_properties(getCategoriesByPostId($page_id));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}