我想知道如何在分类页面上创建播放列表。播放列表将播放与链接到给定类别的帖子相关的所有歌曲/音频文件。
Example如果我有一个名为“福音”的类别,以及10个分配给“福音”的帖子。每个帖子都有一首相关歌曲。因此,总共有10首歌曲。
目标是要有一个播放列表,这样当我转到“福音”的分类页面时,我会看到一个可以播放这10首歌曲的播放列表。当我添加新帖子并将其分配给类别时,它还应该自动同步并播放。
非常感谢您的帮助
我想知道如何在分类页面上创建播放列表。播放列表将播放与链接到给定类别的帖子相关的所有歌曲/音频文件。
Example如果我有一个名为“福音”的类别,以及10个分配给“福音”的帖子。每个帖子都有一首相关歌曲。因此,总共有10首歌曲。
目标是要有一个播放列表,这样当我转到“福音”的分类页面时,我会看到一个可以播放这10首歌曲的播放列表。当我添加新帖子并将其分配给类别时,它还应该自动同步并播放。
非常感谢您的帮助
使用slug“Gorsoph”从类别中获取10篇帖子,在循环中获取帖子子项,按mime类型筛选以获取适当的文件,添加到列表中
/**
* get 10 post from category with SLUG gospel
*/
$args = array(
\'category_name\' => \'gospel\',
\'posts_per_page\' => 10
);
$songs = array();
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
/**
* get post children, filter by post_mime_type, limit 1
*/
$args = array(
\'post_parent\' => get_the_ID(),
\'post_type\' => \'attachment\',
\'posts_per_page\' => 1,
\'post_status\' => \'any\',
\'post_mime_type\' => \'audio\'
);
$attachments = get_children( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$songs[] = wp_get_attachment_url( $attachment->ID);
}
}
}
}
/**
* print songs
*/
print_r($songs);
/**
* reset postdata
*/
wp_reset_postdata();
我有一个帖子类型叫做journal 在single-journal.php 模板我正在查询journal 类似这样的帖子:<?php query_posts( array( \'posts_per_page\' => 4, \'post_type\' => \'journal\', \'paged\' => ( get_query_var(\'page\') ? get_query_var(\'page\') : 1 ),&#x