There are various plugins of "What's New", but what should I do if I create my own?
It would be nice if you could put a short code and display it anywhere you like.
This time we will create a list of post articles.
Put the above code inside "functions.php".
global $post
This is a variable that stores the post. Declare it as a global variable.
If you do not write this, the post title will not be displayed, so be careful.
get_posts($args)
get_posts () is a function that gets posts in an array.The contents of $args, is used as an array.
For example, in this case, you can set the category ID, post type, and number of posts.
There are other items that can be set.
You can see the information from here.
Codex is from here
Loop with foreach
Loop through these to get the title and link for each post.
setup_postdata($post)
The global variable declared earlier is processed by setup_postdata ().
Set so that it recognize the target article is $post.
Output processing
Assign HTML to a variable and return it later.
Here, get_permalink () and get_the_title () are used to get the title and link of the article.
wp_reset_postdata()
$post is used in various places, but this time we are processing to restore the overwritten $post.
add_shortcode()
Finally, register the short_post_article() function in the short code.
The completed shortcode is this.
[list]
You can paste this short code to fixed page, or widget management screen to display the post list.
This article title
Display WordPress "Posted Articles List" in short code