这将起作用:
$latest_post = get_post( array( \'cat\' => YOUR_CAT_ID, \'posts_per_page\' => 1) )
if( $latest_post ) {
echo get_permalink( $latest_post->ID );
}
或者,您可以针对更多类别批量执行此操作:
$categories = array( 7, 12, 14, 15 );
foreach( $categories as $cat ) {
$latest_post = get_post( array( \'cat\' => $cat, \'posts_per_page\' => 1) )
if( $latest_post ) {
echo get_permalink( $latest_post->ID );
}
}