从 WordPress 媒体库类别中获取图像
最近刚刚开始使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用媒体库类别插件,请查看 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
如果您使用的是:media-library-categories.1.0.6 插件,那么您只需执行以下操作即可回显包含特定媒体类别的所有图像的无序列表(将“11”替换为媒体的 ID)您要显示的类别)
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)