从 WordPress 媒体库类别中获取图像

发布于 2024-11-15 03:31:03 字数 374 浏览 8 评论 0原文

最近刚刚开始使用 WordPress,我正在尝试创建一个主页幻灯片。我正在为客户创建自定义主题,并且希望能够对媒体库中的媒体进行分类,因此我使用 这个插件来添加类别,这样我就可以从我创建的“homepageBanner”图库中提取图像。

当我通过 get_posts()、get_children() 或 do_shortcodes() 从模板上的媒体库中提取图像时,它们都不会为我提供返回的对象的属性来确定它们所属的类别。

我想这是以前已经完成过(没有插件),并且似乎是一项非常简单的任务,但是在我查看和搜索的地方,我发现的只是插件。

Just picking up wordpress as of late and I am trying to create a homepage slide show. I am creating a custom theme for a client and I want to be able to categorize media in the media library, so I am using this plugin to add categories so I can just pull the images from the "homepageBanner" gallery that I created.

When I pull images from my media library on my template via get_posts(), get_children() or do_shortcodes(), they all don't give me a property on the objects that are returned to determine what category they are in.

I imagine this has been done before (without a plugin), and seems like an incredibly easy task, however where I look and search, all I am finding are plug-ins.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软甜啾 2024-11-22 03:31:03

如果您使用媒体库类别插件,请查看 media-categories.php 中的 get_category_archive 函数。它在taxonomy-media_category.php 中用于提取存档图像。您可以在主题 function.php 中创建一个自定义函数来执行类似的操作

if you are using the media library categories plugin then check out the function get_category_archive located in the media-categories.php. it is used in the taxonomy-media_category.php to pull archived images. you could create a custom function in your themes function.php that does something similar

苦行僧 2024-11-22 03:31:03

如果您使用的是:media-library-categories.1.0.6 插件,那么您只需执行以下操作即可回显包含特定媒体类别的所有图像的无序列表(将“11”替换为媒体的 ID)您要显示的类别)

<?php echo do_shortcode('[mediacategories categories="11"]');  ?>

If you are using the: media-library-categories.1.0.6 plugin, then you can simply do the following to echo out an unordered list containing all your images for a specific media category (replace "11" with the ID of the media category you want to display)

<?php echo do_shortcode('[mediacategories categories="11"]');  ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文