Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Archive.php按自定义帖子类型筛选_Php_Wordpress - Fatal编程技术网

Archive.php按自定义帖子类型筛选

Archive.php按自定义帖子类型筛选,php,wordpress,Php,Wordpress,我在function.php中有这段代码,我创建了一个创建post的月份列表,如下所示: 2015年11月至12月 2014年10月11月12日 “11月”“12月”是显示url的链接:www.xxx.com/2015/11发布日期 这是使用archive.php实现的 问题是:如果不过滤这些自定义帖子类型链接,你自己怎么能做到这一点 function twentyeleven_get_archives_callback($item, $index, $currYear) { globa

我在function.php中有这段代码,我创建了一个创建post的月份列表,如下所示:

2015年11月至12月

2014年10月11月12日

“11月”“12月”是显示url的链接:www.xxx.com/2015/11发布日期

这是使用archive.php实现的

问题是:如果不过滤这些自定义帖子类型链接,你自己怎么能做到这一点

function twentyeleven_get_archives_callback($item, $index, $currYear) {
    global $wp_locale;

    if ( $item['year'] == $currYear ) {
        $url = get_month_link( $item['year'], $item['month'] );
        // translators: 1: month name, 2: 4-digit year
        $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($item['month']), $item['year']);
        $text = substr($text,0,3);
        echo get_archives_link($url, $text);
    }
}

    function twentyeleven_get_archives() {
            global $wpdb;

            $query = "SELECT YEAR(post_date) AS `year` FROM $wpdb->posts WHERE `post_type` = 'post' AND `post_status` = 'publish' GROUP BY `year` ORDER BY `year` DESC limit 4";
            $arcresults = $wpdb->get_results($query);
            $years = array();

            if ($arcresults) {
                foreach ( (array)$arcresults as $arcresult ) {
                    array_push($years, $arcresult->year);
                }
            }

            $query = "SELECT YEAR(post_date) as `year`, MONTH(post_date) as `month` FROM $wpdb->posts WHERE `post_type` = 'post' AND `post_status` = 'publish' GROUP BY `year`, `month` ORDER BY `year` DESC, `month` ASC";
            $arcresults = $wpdb->get_results($query, ARRAY_A);
            $months = array();

            if ( $arcresults ) {
                foreach ($years as $year) {
                            //My Display
                    //echo "\t<li>\n\t\t<a href=\"#\">$year</a>\n\t\t<ul>\n";
                    //array_walk($arcresults, "twentyeleven_get_archives_callback", $year);
                    //echo "\t\t</ul>\n\t</li>\n";

                            //Your Display
                    echo "\t<div class='listYearArchive'><span class='yearArchive'>$year</span>\n\t<ul class='listMonthArchive'>\n";
                    array_walk($arcresults, "twentyeleven_get_archives_callback", $year);
                    echo "\t</ul></div>\n";
                }
            }
        }
函数twentyeleven\u get\u archives\u回调($item,$index,$currYear){
全球$wp_地区;
如果($item['year']=$currYear){
$url=get_month_链接($item['year',$item['month']);
//翻译人员:1:月名,2:4位年份
$text=sprintf(`1$s%2$d'),$wp\u locale->get\u month($item['month']),$item['year']);
$text=substr($text,0,3);
echo获取存档链接($url,$text);
}
}
函数twentyeleven_get_archives(){
全球$wpdb;
$query=“从$wpdb->posts中选择年份(发布日期)作为'YEAR',其中'post\u type`='post'和'post\u status`='publish'组按'YEAR'按'YEAR'顺序按'YEAR'描述限制4';
$archresults=$wpdb->get_results($query);
$years=array();
如果($arcresults){
foreach((数组)$archresults作为$archresult){
阵列推送($years,$arcsresult->year);
}
}
$query=“从$wpdb->post中选择年(发布日期)作为'YEAR',选择月(发布日期)作为'MONTH',其中'post_type`='post'和'post_status`='publish'按'YEAR'分组,'MONTH'按'YEAR`DESC'顺序,'MONTH`ASC';
$archresults=$wpdb->get_results($query,ARRAY_A);
$months=array();
如果($arcresults){
foreach($年为$年){
//我的显示器
//echo“\t
  • \n\t\t\n\t\t
      \n”; //array_walk($arcresults,“twentyeleven_get_archives_callback”,$year); //回声“\t\t
    \n\t
  • \n”; //你的展示 echo“\t$year\n\t
      \n”; array_walk($arcresults,“twentyeleven_get_archives_callback”,$year); 回声“\t
    \n”; } } }
    您可以在查询中正确更改post\u类型

    FROM $wpdb->posts WHERE `post_type` = 'post'
    
    只需更改自定义帖子名的
    post