ajax problem
-
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….
The topic ‘ajax problem’ is closed to new replies.
