如何创建一个画廊页面,这是一个画廊-使用一个特定的照片从亚画廊作为封面的相册?
这就是我到目前为止所拥有的。
我在后端有一个文件夹,它使用WP媒体文件夹构建,名为master。我希望图片库页面列出master中每个文件夹的缩略图和缩略图所属的图库的名称。
这是我所拥有的。
$galleries = get_terms( 'wpmf-gallery-category', [ 'hide_empty' => 0 ]);
foreach ( $galleries as $gal )
{
if ( $gal->name != 'master' )
{
?>
name ?>我想问题是,如何通过图片所在的文件夹访问图像?我不知道WP文件夹是如何链接到图像的。我需要能够从图片库元素id中查询和获取图像srcs。
发布于 2018-06-21 19:25:47
我为此创建了一个自定义函数,但是如果您想要根文件夹id,可以使用wp cli并使用命令wp term list wpmf-gallery-category来显示所有图片库文件夹。获取要用作根的id项,并将其设置为$master_id
/*
get_root_gallery_id();
Custom function that returns the id of folder with parent id == 0
*/
$master_id = get_root_gallery_id( 'master' );
$galleries = get_terms( 'wpmf-gallery-category', [ 'hide_empty' => 0 ]);
// If there is a root folder
if ( $master_id )
{
foreach ( $galleries as $gal )
{
if ( $gal->parent == $master_id )
{
$args = [
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'inherit'
'tax_query' => [
[
'taxonomy' => 'wpmf-gallery-category',
'terms' => [ $gal->term_id ],
'field' => 'term_id'
]
]
];
$query = new WP_Query( $args );
if ( $query->have_posts() )
{
while ( $query->have_posts() )
{
$query->the_post();
global $post; // Image as Post Object
}
}
}
}
}发布于 2018-06-23 15:24:08
我们使用两个插件来实现这一点而无需编程,更重要的是,我们不必担心每3个months...downside更新一次代码。MLA库(媒体图书馆助理,我认为是实际名称)和内容视图Pro由PT Guy。我不记得免费的让你过滤媒体。
https://wordpress.stackexchange.com/questions/306542
复制相似问题