使用Download Monitor 插件允许我对文件进行分类,所以我将文件放在那里而不是媒体库中。我根据要显示的页面将文件分类。然后,我使用一个带有自定义短代码的文本小部件来显示每页每个类别的文件。
在我的主题功能中。php:
// Enable shortcodes in text widgets
add_filter(\'widget_text\', \'do_shortcode\');
// Custom shortcode:
add_shortcode(\'downloads_by_page\', \'downloads_by_page\');
function downloads_by_page($atts) {
$atts = shortcode_atts(
array(
\'pages\' => array(),
\'category\' => -1, // ID of a Download Monitor category
\'format\' => \'5\' // ID of a Download Monitor output format
),
$atts
);
$pages = $atts[\'pages\'];
if (is_string($pages)) {
$pages = explode(\',\', $pages);
}
if (is_page($pages)) {
// \'downloads\' shortcode comes with Download Monitor:
// http://mikejolley.com/projects/download-monitor/
return do_shortcode(\'[downloads query="category=\' . $atts[\'category\'] .
\'&orderby=title&order=asc" format="\' . $atts[\'format\'] . \'"]\');
}
return \'\';
}
在侧边栏中的文本小部件中:
// Category 3 refers to the ID of the Download Monitor category that has cat-related files
// Pages is a comma-separated list of page names or IDs
[downloads_by_page category="3" pages="About Cats,All Animals"]
[downloads_by_page category="4" pages="About Dogs,All Animals,Canine Facts"]