Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取Wordpress类别或段代码下的文件列表_Php_Wordpress - Fatal编程技术网

Php 如何获取Wordpress类别或段代码下的文件列表

Php 如何获取Wordpress类别或段代码下的文件列表,php,wordpress,Php,Wordpress,我有一个类别,它有子类别,在这些类别下,我有文章作为附件。我只想从这个类别中检索文件,为此我使用了以下代码,但它不起作用 <ul> <?php global $wpdb; $max_posts = 5; $sql = "SELECT posts.ID, attach.ID attachID, attach.post_title, MIN(attach.post_date) FROM $wpdb->posts posts, $wpdb

我有一个类别,它有子类别,在这些类别下,我有文章作为附件。我只想从这个类别中检索文件,为此我使用了以下代码,但它不起作用

<ul>
    <?php
    global $wpdb;
    $max_posts = 5;
    $sql = "SELECT posts.ID, attach.ID attachID, attach.post_title, MIN(attach.post_date)
    FROM $wpdb->posts posts, $wpdb->posts attach
    WHERE posts.ID = attach.post_parent
    AND attach.post_type='attachment'
    AND attach.post_status = 'inherit'
    AND posts.post_type = 'post'
    AND posts.post_status = 'publish'
    AND posts.post_date <= NOW()
    GROUP BY posts.ID
    ORDER BY posts.post_date DESC
    LIMIT $max_posts";

    $postIDs = $wpdb->get_results($sql);
    foreach ($postIDs as $postID) {
    the_attachment_link($postID->attachID,false);


    }
    ?>
    </ul>

    我想你应该用这个

    <?php
    
    // The Query
    $the_query = new WP_Query( 'cat=13&post_type=publication&numberposts=5' );
    
    // The Loop
    
         while ( $the_query->have_posts() ) : $the_query->the_post();
    
                echo '<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>';
    
    
         endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>