options = get_option('apc_option'); echo '
'; settings_fields('apc_option_group'); echo ''; echo ''; echo ' '; echo ''; echo ''; echo ' '; echo ' '; echo ''; echo ''; echo '
'.__( 'Options for Ajax PostContent', 'ajax-posts-content' ).'
'.__( 'Only admin (test mode)','ajax-posts-content' ).' options["apc_test"]) ? true : false),true,false). ' />
'.__( 'Article block', 'ajax-posts-content' ).':
'.__( 'Where to upload new posts? Element selector', 'ajax-posts-content' ).'
'.__( 'Download type', 'ajax-posts-content' ).':
'.__( 'The queue of posts', 'ajax-posts-content' ).':
'.__( 'Count Loads', 'ajax-posts-content' ).':
'.__( 'Maximum ajax downloads. "-1" - no restrictions', 'ajax-posts-content' ).'
'.__( 'Height from bottom', 'ajax-posts-content' ).':
'.__( 'The height from the bottom of the document to start loading (scroll)', 'ajax-posts-content' ).'
'.__( 'Enable on mobile','ajax-posts-content' ).' options["apc_mobile"]) ? true : false),true,false). ' />
'.__( 'Enable on desktop','ajax-posts-content' ).' options["apc_desktop"]) ? true : false),true,false). ' />
'; /*Выбор типов постов где будет работать*/ echo ''; $post_types = get_post_types(array('public'=> true),'names'); foreach( $post_types as $post_type ){ echo ''; } echo ""; echo '
'.__( 'Enable for types & Template:', 'ajax-posts-content' ).'
'.__( $post_type, 'ajax-posts-content' ).': options["apc_type_".$post_type]) ? 'true' : 'false').'"'. checked((!empty($this->options["apc_type_".$post_type]) && boolval($this->options["apc_type_".$post_type]) ? 'true' : 'false'),'true',false). ' /> {theme_dir}/
". __( 'If the field is empty, the standard template will be used: "[plugin_girectory]/template/def.php"', 'ajax-posts-content' )."
'; submit_button(''.__( 'SaveSettings', 'ajax-posts-content' ).''); echo '
'; ?> true),'names'); foreach( $post_types as $post_type ) { add_settings_field('apc_type_'.$post_type, '','apc-settings','apc_section_2' ); add_settings_field('apc_template_'.$post_type, '','apc-settings','apc_section_3' ); } //Стандартные значения tckb if(empty(get_option('apc_option'))) { $default_settings = array( 'apc_article_block' => 'article', 'apc_сount' => '3', 'apc_type' => 'scroll', 'apc_order' => 'cat', 'apc_test' => '0', 'apc_type_post' => 'true', 'apc_desktop' => 'true', 'apc_mobile' => 'true', 'apc_mobile' => '100', ); update_option('apc_option',$default_settings, ""); } } } if( is_admin() ) $apc_settings_page = new AjaxPostsContent(); //////////////////////// /*Обаботчик*/ function apc_get_content_post(){ $apc_option = get_option('apc_option'); $args['post_type'] = get_post_type(sanitize_text_field($_POST['this_id'])); /*Рандом*/ if ($apc_option['apc_order']=='rand' || empty($apc_option['apc_order'])) $args['orderby'] = 'rand'; /*Одинаковые категории + Рандом или новые*/ elseif($apc_option['apc_order']=='cat' || $apc_option['apc_order']=='new') { $cats = get_the_category(sanitize_text_field($_POST['this_id'])); if ($cats) $args['cat'] = $cats[0]->cat_ID; if($apc_option['apc_order']=='cat') $args['orderby'] = 'rand'; } $args['post__not_in'] = explode(",", sanitize_text_field($_POST['not_in'])); $args['posts_per_page'] = 1; //query_posts( $args ); $query = new WP_Query($args); while( $query->have_posts() ): $query->the_post(); $file_template=$apc_option['apc_template_'.get_post_type(get_the_ID())]; //Шаблон сушествует - грузим! if(!empty($file_template)) get_template_part(str_replace(".php","",$file_template)); else include 'template/def.php'; echo(''); endwhile; die(); } add_action('wp_ajax_loadmore', 'apc_get_content_post'); add_action('wp_ajax_nopriv_loadmore', 'apc_get_content_post'); /*Функция вывода*/ function apc_load_post_ajax(){ $apc_option = get_option('apc_option'); require_once ('style.php'); // Режим темтирования или глобальный режим if(is_single() && ((!empty($apc_option['apc_test']) && $apc_option['apc_test']=='true' && is_user_logged_in()) || empty($apc_option['apc_test']))): // Выставлено кол-во и открыт правильный тип поста if(!empty($apc_option['apc_сount']) && $apc_option['apc_type_'.get_post_type(get_the_ID())]=='true' ): // Включен или мобильный или десктопный режим if(($apc_option['apc_mobile']==true && wp_is_mobile()) || ($apc_option['apc_desktop']==true && !wp_is_mobile())): ?>