我正在尝试显示一个随机wordpress模板中的3个,对于以“b”开头的slugs的页面。我有这段代码:
$current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
$slug = $current_page->post_name;
$slugBeginsWith = substr($slug, 0, 1);
if($slugBeginsWith == 'a')
{
get_template_part( 'templates/template1' );
}
elseif($slugBeginsWith == 'b')
{
$table = array(get_template_part( 'templates/template1' ), get_template_part( 'templates/template2' ), get_template_part( 'templates/template3' ));
echo $table[array_rand($table)];
}
hovewer这让我全部显示3个带有“b”slugs的页面。我该如何纠正?