首页 文章

如何检索所有附件,但有2页的附件

提问于
浏览
0

我正在为我的客户开发一个自定义主题 . 我想要做的是通过wp_getposts(http://codex.wordpress.org/Function_Reference/get_posts)检索安装中的所有附件(=图像) .

该代码将是:

$ attachments = get_posts('post_type = attachment&numberposts = -1');

foreach(附件为$ att)....等等

然后我对图像做了一些事情,最后用页面中的图像创建图像幻灯片 .

现在是棘手的部分,我想在installatie(客户端请求)中排除2个特定页面的附件,我真的不知道该怎么做 .

这里有任何wordpress向导吗?

2 回答

  • 0

    拜伦以前的代码答案:)

    $excluded_parents = array(1, 4, 7); // IDs of excluded parent posts
    
    foreach ($attachments as $att) {
        if (in_array($att->post_parent, $excluded_parents))
            continue;
    
        // carry on coding!
    }
    
  • 1

    你不能只看一下附件的ID或 Headers 并跳过它吗?它将是硬编码而不是非常优雅,但它会工作 .

    更具扩展性的方法是为附件分配标签,例如“不显示”,并忽略带有此标签的所有附件 .

相关问题