Title: ajax problem
Last modified: August 30, 2016

---

# ajax problem

 *  [EntropiaStas](https://wordpress.org/support/users/entropiastas/)
 * (@entropiastas)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/ajax-problem-14/)
 * hello, guys!
 * First of all I want to say thanks for such good theme!
 * In one of my projects, I need to create dynamic archive of one of the categories.
   
   I search for a right plugin for a long time. But I can’t find them. But I find
   some solution.
 * template for page:
 *     ```
       <?php
       /*
       	Template Name: Шаблон архивов
       */
       ?>
   
       <?php get_header(); ?>
   
       <style type="text/css" rel="stylesheet" >
       #archive_browser > div { display: inline-block; padding-right: 10px; }
       #archive_pot { min-height:150px; }
       #archives_table { border-collapse:collapse; margin:15px 0 0 0; width:100%; }
       #archives_table td { min-height:25px; padding:4px; border-top:1px solid #eee; border-bottom:1px solid #eee; }
       </style>
   
       <script type="text/javascript">
       (function($){
       	$(function(){
   
       		$("#archive_browser select").change(function(){
       			$("#archive_pot")
       	.empty()
       	.html("<div style='text-align:center; padding:30px;'><img src='<?php bloginfo('template_url') ?>/images/ajax-loader.gif' /></div>");
       	var dateArray = $("#month-choice").val().split("/");
       			var y = dateArray[3];
       			var m = dateArray[4];
       			var c = $("#cat").val();
       	$.post(
       	"<?php bloginfo('template_url') ?>/scripts/archive_getter.php",
       	{
       		year : y,
       		month : m,
       		cat : c
       	},
       	function(data) {
       		$("#archive_pot").html(data).animate({ height: $("#archives_table").height()+40 });
       	}
       	);
       		});
       	});
       })(jQuery)
       </script>
   
       <div id="archive_browser">
       	<div>
       		<h4>Месяцы</h4>
       		<select id="month-choice">
       			<option val="no-choice"> — </option>
       			<?php wp_get_archives(array(
       	'type' => 'monthly',
       	'format'  => 'option'
       			)); ?>
       		</select>
       	</div>
       	<div>
       		<h4>Рубрики</h4>
       		<?php wp_dropdown_categories('show_option_none= -- '); ?>
       	</div>
       </div>
   
       <div id='archive_pot'></div>
   
       <?php get_footer(); ?>
       ```
   
 * GETTER:
 *     ```
       <?php 
   
       // подгружаем среду WP
       require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
   
       // фильтруем POST данные, передаваемые этому файлу с Javascript
       $year = htmlspecialchars(trim($_POST['year']));
       $month = htmlspecialchars(trim($_POST['month']));
       $cat = htmlspecialchars(trim($_POST['cat']));
   
       ?> 
   
       <table id="archives_table">
       	<?php
       	if( ($year=='') && ($month=='') && ($cat=='-1') ){
       		echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Пожалуйста, выберите дату/категорию из списка выше.</td></tr>";
       	}
       	else
       	{
       		// Получаем данные с помощью query_posts
       		query_posts("posts_per_page=-1&cat=$cat&monthnum=$month&year=$year");
       		// выводим данные в Цикле WordPress
       		if( have_posts() ){ while( have_posts() ){ the_post(); ?>
       			<tr>
       	<td><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></td>
       	<td><?php comments_popup_link(' ', '1 Комментарий', '% Комментариев'); ?></td>
       	<td><?php the_time('j.m.Y'); ?></td>
       			</tr>
       			<?php
       		}}
       		else // Если постов нет
       			echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Ничего не найдено.</td></tr>";
       	} ?>
       </table>
       ```
   
 * AND code that I put to ajax-hendler.php
 *     ```
       function my_scripts_method() {
       	wp_deregister_script( 'jquery' );
       	wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
       	wp_enqueue_script( 'jquery' );
       }    
   
       add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
       ```
   
 * It was some problems with russian symbols, I solve this problem by changing windows
   to utf-8 in ajax-hendler.
 * In page template I write category that I need in query_posts.
 * But I have problem. After month choosing, page show posts for needed category,
   but for all dates – all posts in this category. I try to switch month and year,
   but page show all posts again.
 * I try to change date formats in wordpress setting, but nothing…
 * Help please….

Viewing 1 replies (of 1 total)

 *  Thread Starter [EntropiaStas](https://wordpress.org/support/users/entropiastas/)
 * (@entropiastas)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/ajax-problem-14/#post-6410173)
 * help somebody, plz:)

Viewing 1 replies (of 1 total)

The topic ‘ajax problem’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/graphene/2.9.4/screenshot.jpg)
 * Graphene
 * [Support Threads](https://wordpress.org/support/theme/graphene/)
 * [Active Topics](https://wordpress.org/support/theme/graphene/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/graphene/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/graphene/reviews/)

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)

 * 1 reply
 * 1 participant
 * Last reply from: [EntropiaStas](https://wordpress.org/support/users/entropiastas/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/ajax-problem-14/#post-6410173)
 * Status: not resolved