如何检索除 2 页之外的所有附件
我目前正在为我的客户开发一个自定义主题。我想要做的是通过 wp_getposts (http:// codex.wordpress.org/Function_Reference/get_posts)。
该代码为:
$attachments = get_posts('post_type=attachment&numberposts=-1');
foreach ($attachments as $att) .... 然后
我对图像进行一些处理,最终使用页面中的图像创建一个图像幻灯片。
现在棘手的部分是,我想排除安装中 2 个特定页面的附件(客户端请求),但我真的不知道如何去做。
这里有 WordPress 向导吗?
I'm currently developing a custom theme for a client of mine. What I want to do is retrieve all the attachments (= images) in the installation via wp_getposts (http://codex.wordpress.org/Function_Reference/get_posts).
That code would be:
$attachments = get_posts('post_type=attachment&numberposts=-1');
foreach ($attachments as $att) .... and so on
I then do some stuff to the images to finally create an image slideshow with the images from the pages.
Now the tricky part, I want to exclude the attachments of 2 specific pages in the installatie (client request) and I don't really know how to go about this.
Any wordpress wizards around here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道你不能只看附件的 ID 或标题并跳过它吗?它会是硬编码的并且不是很优雅,但它会起作用。
一种更具扩展性的方法是为附件分配一个标签,例如“no-show”并忽略带有此标签的所有附件。
Can't you just look at the ID or title of the attachment and skip it? it would be hard coded and not very elegant, but it would work.
A more extensible way would be to assign a tag to the attachment, such as "no-show" and ignore all attachments with this tag.
拜伦之前在代码中的回答:)
Byron's former answer in code :)