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();
?>