我已经安装了下载监视器插件,它工作得很好,我只是有一个关于类别的问题。
我有一个父类别,第0期,其中将有3-6个子类别。与首页下面的部分不同,它只列出父类别中的每个下载,而不考虑子类别,
我怎样才能使它类似于下面的结构,它实际上使用了类别,单击子类别可以访问其所有下载:
问题0(7)>>
糖尿病新闻世界观采访(这些需要保持链接,如上所述)
下面是download\\u页面短代码的代码,是否有方法将子类别合并到此功能中?
function wp_dlmp_shortcode_download_page( $atts ) {
extract(shortcode_atts(array(
\'base_heading_level\' => \'3\',
\'pop_count\' => \'4\',
\'pop_cat_count\' => \'4\',
\'show_uncategorized\' => \'1\',
\'per_page\' => \'20\',
\'format\' => \'\',
\'exclude\' => \'\',
\'exclude_cat\' => \'\',
\'show_tags\' => \'0\',
\'default_order\' => \'title\',
\'front_order\' => \'hits\'
), $atts));
$output = wp_dlmp_output($base_heading_level, $pop_count, $pop_cat_count, $show_uncategorized, $per_page, $format, $exclude, $exclude_cat, $show_tags, $default_order, $front_order);
return $output;
}
add_shortcode(\'download_page\', \'wp_dlmp_shortcode_download_page\');
?>
最合适的回答,由SO网友:brasofilo 整理而成
从documentation and its sample code, 我看不到获取下载类别树的选项。
功能get_downloads
返回aone-dimensional array. 也许是routine 可以将其转换为多维数组。
使用此选项可查看其内容:
$dl = get_downloads();
echo \'<pre>\' . print_r($dl, true ) . \'</pre>\';
另一种可能性是由包含所有类别的插件的全局变量提供的:
global $download_taxonomies;
echo \'<!-- <pre>\' . print_r( $download_taxonomies->categories, true ) . \'</pre> -->\';
结果是:
Array
(
[1] => download_category Object
(
[id] => 1
[name] => util
[parent] => 0
[decendents] =>
[direct_decendents] =>
[size] => 51
)
[2] => download_category Object
(
[id] => 2
[name] => sys
[parent] => 0
[decendents] => Array
(
[0] => 5
[1] => 7
[2] => 8
)
[direct_decendents] => Array
(
[0] => 5
[1] => 7
)
[size] => 3
)
[5] => download_category Object
(
[id] => 5
[name] => mac
[parent] => 2
[decendents] => Array
(
[0] => 8
)
[direct_decendents] => Array
(
[0] => 8
)
[size] => 4
)
[7] => download_category Object
(
[id] => 7
[name] => windows
[parent] => 2
[decendents] =>
[direct_decendents] =>
[size] => 0
)
[8] => download_category Object
(
[id] => 8
[name] => ipad
[parent] => 5
[decendents] =>
[direct_decendents] =>
[size] => 0
)
)
使用这个数组,可以构建一个逻辑来迭代元素并显示类别层次结构。
使用短代码演示。请注意digforcats
必须为空值:
add_shortcode(\'download_cats\', \'wpse_73425_download_categories\');
function wpse_73425_download_categories( $atts )
{
global $download_taxonomies;
foreach( $atts as $key=>$value )
$query .= \'&\' . $key . \'=\' . $value;
$the_cats = \'<br><br>Download Categories:\';
foreach( $download_taxonomies->categories as $category )
{
if( $category->parent == 0 )
{
$the_cats .= \'<br><b>\' . $category->name . \'</b><br>\';
$dl = get_downloads(\'category=\'.$category->id.$query.\'&digforcats=\');
foreach($dl as $d)
{
$the_cats .= \'<br><a href="\'
.$d->url . \'" title="Version \'
.$d->version . \' downloaded \'
.$d->hits.\' times" >\'
.$d->title.\' (\'.$d->hits.\')</a>\';
}
if( isset( $category->direct_decendents ) )
{
foreach( $category->direct_decendents as $cat )
{
$the_cats .= \'<br>- - <i>\'
. $download_taxonomies->categories[$cat]->name
. \'</i><br>\';
$dl = get_downloads(\'category=\'.$cat.$query.\'&digforcats=\');
foreach($dl as $d)
{
$the_cats .= \'<br><a href="\'
.$d->url.\'" title="Version \'
.$d->version . \' downloaded \'
.$d->hits.\' times" >\'
.$d->title.\' (\'.$d->hits.\')</a>\';
}
}
}
}
}
return $the_cats;
}
插件页面和短代码输出的屏幕截图: