Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * FacetWP Modifications
- *
- **/
- /*=====================================================
- = CAF Settings Scrolltop option =
- =====================================================*/
- add_action('wp_head', 'caf_fwp_scrolltop_js');
- function caf_fwp_scrolltop_js(){
- $CAF_Settings = get_option('CAF_Settings', array());
- if( $CAF_Settings['opt-caf-fwp-scrolltop-refresh']){
- echo '<script type="text/javascript">var CAF_FWP_scrolltop = true;</script>';
- } else{
- echo '<script type="text/javascript">var CAF_FWP_scrolltop = false;</script>';
- }
- }
- /*===========================================
- = Altering Pager Text =
- ===========================================*/
- add_filter( 'facetwp_pager_html', 'caf_facetwp_pager_html', 10, 2 );
- function caf_facetwp_pager_html( $output, $params ) {
- global $CAF_Settings;
- if( $first_text = $CAF_Settings['opt-caf-fwp-pager-first-text'])
- $output = str_replace('<<', $first_text, $output);
- if( $last_text = $CAF_Settings['opt-caf-fwp-pager-last-text'])
- $output = str_replace('>>', $last_text, $output);
- return $output;
- }
- /*==============================================================
- = Alter Sort Results, Add Items Per Page =
- ==============================================================*/
- //add_filter( 'facetwp_sort_html', 'caf_facetwp_sort_html', 10, 2 );
- function caf_facetwp_sort_html( $html, $params ) {
- global $CAF_Settings;
- $html = '<select class="facetwp-sort-select">';
- foreach ( $params['sort_options'] as $key => $atts ) {
- $html .= '<option value="' . $key . '">' . $atts['label'] . '</option>';
- }
- $html .= '</select>';
- return $html;
- }
- /*=======================================================
- = Custom Items Per Page Shortcode =
- =======================================================*/
- add_shortcode( 'caf_facetwp','caf_facetwp_custom' );
- function caf_facetwp_custom( $atts ) {
- global $CAF_Settings;
- $html = '';
- $atts = extract( shortcode_atts( array(
- 'itemsperpage'=>false
- ),$atts ) );
- if( $itemsperpage){
- $html .= '<div class="facetwp-itemsperpage caf-facetwp"><select class="caf-fwp-items-per-page">';
- foreach($CAF_Settings['opt-caf-fwp-items-per-page'] as $item){
- $val = explode(':', $item);
- $label = isset($val[1]) ? $val[1] : $val[0];
- $html .= '<option value="'.$val[0].'">'.$label.'</option>';
- }
- $html .= '</select></div>';
- }
- return $html;
- // do shortcode actions here
- }
- /*=============================================
- = Altering Sort Options =
- =============================================*/
- /*
- These fields are JSON-encoded and entered in the Redux Options framework
- {"price_desc": { "label": "Price (Lowest)", "query_args": { "orderby": "meta_value_num", "meta_key":"caf_regular_price", "order": "DESC" } } }
- {"price_asc": { "label": "Price (Highest)", "query_args": { "orderby": "meta_value_num", "meta_key":"caf_regular_price", "order": "ASC" } } }
- {"year_desc": { "label": "Year (Oldest)", "query_args": { "orderby": "meta_value", "meta_key":"caf_year", "order": "DESC" } } }
- {"year_asc": { "label": "Year (Newest)", "query_args": { "orderby": "meta_value", "meta_key":"caf_year", "order": "ASC" } } }
- */
- add_filter( 'facetwp_sort_options', 'caf_facetwp_sort_options', 10, 2 );
- function caf_facetwp_sort_options( $options, $params ) {
- global $CAF_Settings;
- if( !empty($CAF_Settings['opt-caf-fwp-sort-options'])){
- $options = array();
- foreach($CAF_Settings['opt-caf-fwp-sort-options'] as $opt){
- if( $option = json_decode($opt, true) ){
- // Get first key of object
- $keys = array_keys($option);
- // Add to options array
- $options[$keys[0]] = $option[$keys[0]];
- } // if decode successful
- } // foreach search option
- } // if search options set
- echo '<pre style="height:120px;overflow-y:scroll;resize:both;">facetwp_sort_options(): $options = '.print_r($options, true).'</pre>';
- return $options;
- }
- /*======================================================
- = Alter Query for Items per Page =
- ======================================================*/
- add_filter( 'facetwp_query_args', 'caf_facetwp_query_args', 10, 2 );
- function caf_facetwp_query_args( $query_args, $class ) {
- if ( isset( $class->http_params['per_page'] ) ) {
- $query_args['posts_per_page'] = (int) $class->http_params['per_page'];
- }
- echo '<pre style="height:120px;overflow-y:scroll;resize:both;">facetwp_query_args(): $query_args = '.print_r($query_args, true).'</pre>';
- return $query_args;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement