【问题标题】:List the attached PDF, and category from posts. Wordpress列出附加的 PDF 和帖子中的类别。 WordPress
【发布时间】:2013-05-06 14:32:28
【问题描述】:

我正在尝试制作一个自定义 Wordpress 模板/页面,在其中列出了几个子类别中帖子的附加 PDF。 我找到了几个 sn-ps,但我无法让它们工作。 我的 PHP 技能有些局限。

这让我得到了所有附加的 PDF,但我想要 4 个不同的列表,每个类别一个。

<?php
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_mime_type' => 'application/pdf',
    'post_parent' => null,
    ); 
    $attachments = get_posts($args);
    if ($attachments) {
        foreach ($attachments as $post) {
            setup_postdata($post); 
    ?>
        <ul class="">
            <li class=""><h2>Sub-Category-Name</h2>
                <ul>
                <li>
                <?php
                the_attachment_link($post->ID, false);
                echo '</li>';
                }
                } 
                ?>

【问题讨论】:

标签: wordpress file list pdf attachment


【解决方案1】:

我已经设法在一定程度上解决了它。现在我在页面上运行了四次,每次循环使用不同的类别名称。

                <ul>
                <?php query_posts('category_name=your-category-name &posts_per_page=-1'); ?>
                    <?php while (have_posts()) : the_post(); ?>
                        <?php
                            $args = array(
                                'order'          => 'ASC',
                                'post_type'      => 'attachment',
                                'post_parent'    => $post->ID,
                                'post_mime_type' => 'application/pdf',
                                'post_status'    => null,
                                'numberposts'    => 1,
                                );
                                $attachments = get_posts($args);
                                if ($attachments) {
                                    foreach ($attachments as $attachment) {
                                        echo "<li><a href='";
                                        echo the_permalink();
                                        echo "' title='";
                                        echo the_title();
                                        echo "'>";
                                        echo the_attachment_link($attachment->ID);
                                        echo "</a></li>";
                                        }
                                    }
                                    ?>
                    <?php endwhile;?>
                </ul>
                <?php wp_reset_query(); ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    相关资源
    最近更新 更多