在调整“Bryans Childpage缩略图生成器”插件时,我将过滤器(带分页)应用于WP页面的get\\u帖子(post_type=page
), 但这根本不是过滤。代码如下:
extract(shortcode_atts(array(
\'order\' => \'ASC\',
\'orderby\' => \'title\',
\'id\' => \'\',
\'number\' => -1,
\'height\' => \'100\',
\'width\' => \'\',
\'size\' => \'thumbnail\',
\'style\' => \'\',
\'include\' => \'\',
\'pagetitle\' => false,
\'selector\' => \'h2\',
\'selector_height\' => \'30px\',
\'selector_width\' => \'100%\',
\'selector_padding\' => \'\',
\'showimages\' => true,
\'text_align\' => \'left\',
\'text_margin\' => \'\',
\'exclude\' => \'\',
\'posts_per_page\' => \'5\',
\'page_number\' => \'1\',
\'filter_year\' => \'0\'
), $attr));
if( $id == \'\')
{
$id = $post->ID;
}
$id = intval($id);
if($width != null)
{
$width=\'width:\' . $width . \'px\';
}
if ($order == \'RAND\')
{
$orderby = \'none\';
}
if($text_margin == \'\')
{
$textmargin = ($height/2)-10;
$textmargin .= "px 0 0 0";
} else
{
$textmargin = $text_margin;
}
$offsettext = ($height*3);
$offset = ($page_number - 1) * $posts_per_page;
$offset = $offset < 1 ? 0 : $offset;
function filter_where( $where = \'\' ) {
if($filter_year > 0)
$where .= " AND post_date >= \'" . $filter_year . "-01-01\' AND post_date < \'" . ($filter_year + 1) . "-01-01\'";
// e.g. AND post_date >= \'2011-01-01\' AND post_date < \'2012-01-01\'
return $where;
}
add_filter( \'posts_where\', \'filter_where\' );
$countposts = count(get_posts(array(
\'suppress_filters\' => false,
\'post_parent\' => $id,
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
\'numberposts\' => $number,
\'exclude\' => $exclude,
\'orderby\' => $orderby
)));
$childpages = & get_posts(array(
\'suppress_filters\' => false,
\'post_parent\' => $id,
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
\'numberposts\' => $number,
\'exclude\' => $exclude,
\'orderby\' => $orderby,
\'order\' => $order,
\'posts_per_page\' => $posts_per_page,
\'offset\' => $offset
));
remove_filter( \'posts_where\', \'filter_where\' );
$totalpages = $countposts / $posts_per_page;
$totalpages = intval($totalpages) + ($totalpages > intval($totalpages) ? 1 : 0);
下面是调用此插件的短代码:
<?php echo do_shortcode("[gallery_childpages number=\'-1\' height=\'220\' width=\'295\' size=\'medium\' style=\'armthumbs\' include=\'\' pagetitle=\'1\' selector=\'H2\' showimages=\'0\' showimages=\'true\' exclude=\'1,33,22\' posts_per_page = \'9\' page_number=\'" . get_query_var(\'page\') . "\' filter_year=\'" . $_GET[\'fyear\'] . "\']"); ?>
分页正在工作,但筛选器不工作。。