Insert recent articles into WordPress (code)

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.

Insertar artículos recientes en WordPress código

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.

<span style=»font-size:22px;» text-align:=»»>
<?php $myposts = get_posts(‘numberposts=5&offset=2’);
foreach($myposts as $post) { ?>
<li><a href=»<?php the_permalink(); ?>»><?php the_title();?></a></li>
<?php } ?>

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.

Insert recent articles into WordPress (code)
This morning, while checking my email I found an email that came from Payp...

Adsense is, at present, the largest advertising system in the entire web, ...

In the territory of SEO, it is always good to review the keywords of our w...

For some time I was looking for some option through which I could show on ...

Bibliography ► (June 26, 2019). Insert recent articles into WordPress (code). Bogotá: E-Cultura Group. Recovered from