Web Shakehands
Web Shakehands

Language


Display WordPress "Posted Articles List" in short code



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

Previous article Use add_theme_support() to set custom header for WordPress


WordPress Theme creation Article !

2019-08-24 The priority order of the WordPress template file NEW!


2019-08-22 Display WordPress "Posted Articles List" in short code


2019-08-01 Use add_theme_support() to set custom header for WordPress


2019-07-24 How to correctly write "hard-coded URL" in wordPress theme


2019-07-19 TGM Plugin Activation is a tool that can install a plugin from WordPress theme


2019-07-13 How to use Bootstrap inside WordPress theme


See all the articles list

Just enter your E-mail and you will receive free
mail magazine about how to make your website etc.
E-mail:
  

Go to top