我想显示所有帖子,如mywebsite.com/postname/1/
, mywebsite.com/postname/2/
...... mywebsite.com/postname/7/
..
下面的代码非常适合我,唯一的问题是它只显示第一篇帖子mywebsite.com/postname/
...
我该怎么做?
<?php
/**
* Template Name: Random Post
* This template will only display the content you entered in the page editor
*/
?>
<html>
<head>
</head>
<body>
<?php
/*
Random Post Picker
Use on page to send viewer to random post optionally mod query
*/
// set arguments for WP_Query on published posts to get 1 at random
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'orderby\' => \'rand\',
\'order\' => \'DESC\',
// Using the date_query to filter posts from last week
\'date_query\' => array(
array(
\'after\' => \'2 week ago\'
)
)
);
// It\'s time! Go someplace random
$my_random_post = new WP_Query ( $args );
while ( $my_random_post->have_posts () ) {
$my_random_post->the_post ();
// redirect to the random post
wp_redirect ( get_permalink () );
exit;
}
?>
</body>
</html>