很高兴看到利物浦站在榜首!
我会使用页面模板来实现这一点。据我所知,我们只知道页面名称,因此我将以这种方式添加它。
过程如下:
循环浏览顶级页面以数组形式收集子页面循环浏览子页面循环浏览子附件
<?php
/*
Template Name: All images
*/
get_header();
// pages to loop through
$sports = array( \'Hockey\', \'Football\' );
// empty array where we collect teams
$teams = array();
// collect teams
foreach( $sports as $sport ) {
$page = get_page_by_title( $sport );
$teams = array_merge(
get_children( array(
\'post_parent\' => $page->ID,
\'numberposts\' => -1,
\'post_type\' => \'page\'
) ),
$teams
);
}
// you could do some custom sorting or randomisation of the order here
// loop through teams
foreach( $teams as &$team ) {
// get image attachments for each team
$images = get_children( array(
\'post_parent\' => $team->ID,
\'numberposts\' => -1,
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\'
) );
// output images
foreach( $image as &$image ) {
// link to team page
echo \'<a href="\' . get_permalink( $team->ID ) . \'">\';
echo wp_get_attachment_image( $image->ID, \'medium\' );
echo \'</a>\';
}
}
get_sidebar();
get_footer();
您需要稍微修改标记,并记住这将非常缓慢,因此您可能需要考虑使用缓存插件。