Using the function that WordPress brings it is possible to insert a widget into the horizontal bar without complicate any, and you can set the number of recent posts that you want to display in the sidebar. However, what if we don’t want to show it in the sidebar, but anywhere else in our theme? For example at the end of the article, in searches, in the footer, etc.
Insert recent articles into WordPress code
Using a simple code it is possible to show the latest articles that we have published on our website,in our blog managed with Wodpress, to do so we only have to insert the following code right in the place that we want it to appear.
To do this, we must edit the .php file in which we want to insert them.
Several variables have been defined in the code that we can modify according to what we need to implement. These include the font size, the post number to display (numerposts), or the post number, from the last one we want to omit (offset).
The sample code set that value to 2. This means that where the code is inserted, the last post will be displayed, except for the last two posts that have been published.
If we simply don’t want to omit any,we set that value to 0. With this we will have the post anywhere we want. Sometimes it can be useful, for example, to put it inside a page not found, so that it does not look so empty, etc.
Phoneia.com (June 26, 2019). Insert recent articles into WordPress (code). Recovered from https://phoneia.com/en/technology/insert-recent-articles-into-wordpress-code/