在wordpress中按$ _POST [date]显示帖子 [英] display post by $_POST[date] in wordpress

查看:276
本文介绍了在wordpress中按$ _POST [date]显示帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要在Wordpress中解决有关显示和过滤数据的问题. 我有这种形式的html,所以首先我有两个下拉列表( DDL ),应该与帖子的日期有关.第一个DDL应该包含所有发布年份,第二个DDL应该包含所有发布月份.

I really need help for this problem in wordpress about displaying and filtering datas. I have html in this form, so first i have two drop down list(DDL), which should be populated related to the date of the posts. First DDL it should contains all the years of the posts, and second DDL should contains all the months of the posts.

<select name="month">
    <option value="2001"> 2001</option>                                                                        
    <option value="2002"> 2002</option>                                                                        
    <option value="2003"> 2003</option>                                                                      
    <option value="2004"> 2004</option>                                                                          
    <option value="2005"> 2005</option>                                                                      
    <option value="2006"> 2006</option>                                                                        
    <option value="2008"> 2008</option>                                                                            
   <option value="2000"> 2000</option>                                             
</select>



<select name="month">
        <option value="January"> 01 </option>                                                                        
        <option value="Feburary"> 02 </option>                                                                        
        <option value="March"> 03 </option>                                                                      
        <option value="April"> 04 </option>                                                                          
        <option value="June"> 06 </option>                                                                      
        <option value="July"> 07 </option>                                                                        
        <option value="August"> 08 </option>                                                                            
       <option value="December"> 12 </option>                                             
    </select>

现在,我需要通过选择DDL,月份和年份来显示帖子.我正在使用while循环 显示所有帖子.像这样:

Now I need to display the posts by selecting in DDL, month and year. I'm using while loop to display all the posts. Something like this:

<?php
    $posts_per_row = 3;
    $posts_per_page = 6;
    $category_name = 'music';
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
         'category_name' => $category_name,
         'posts_per_page' => $posts_per_page,
         'paged' => $paged,
    );
    query_posts($args);
    if (have_posts()) {
       while (have_posts()) {
       the_post();
       ....
    }
} else {
    ....                    
}
?>          

模板在functions.php中还具有分页功能

The template also has the pagination function in functions.php

推荐答案

通过使用year和monthnum参数,您可以基于发布的月份/年份显示帖子. .wordpress.org/Function_Reference/query_posts"rel =" nofollow> query_posts() .

You can display posts based on the posted month/year by using the year and monthnum arguments for query_posts().

// you have "month" in your HTML instead of "year"
$year = $_POST['year'];   
$month = $_POST['month']; 
$args = array(
     'category_name' => $category_name,
     'posts_per_page' => $posts_per_page,
     'year' => $year,
     'monthnum' => $month,
     'paged' => $paged,
);

这篇关于在wordpress中按$ _POST [date]显示帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆