Discover in this tutorial how to show the number of posts from another website that update automatically using a custom shortcode.
In previous tutorials you have already seen how to display the number of entries of your website dynamically using a shortcode.
But what if you want to do the same with the articles of another page?
Maybe it sounds strange to you, but imagine that you have two websites that are related in some way and you are interested in doing this.
With an example you can understand it better
If I want to show the number of tutorials available in OsomCode from my personal brand website nbadiola.com, how would I do it?
Well, thanks to the REST API and a custom shortcode, like this:
Instructions to generate a shortcode to display the number of posts from another website always updated
1. Create the shortcode
Imagine you want to get a text similar to:
If you are interested in continuing to learn more in OsomCode you have X tutorials available.
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
This snippet shows the number of normal entries (in this case tutorials) of OsomCode site, accessed via the REST API.
Thus, to get the previous sentence you would have to type
If you are interested in continuing to learn more in OsomCode you have [external_post_number] tutorials available.
This is just an example, you know you can adapt it to your liking (you just have to change the URL). You don’t need to go advertising OsomCode on your website (or yes, I’m not going to oppose). ๐
2. Insert the shortcode where you want
The advantage of shortcodes is that you can insert them anywhere on the web.
Just type “[your_shortcode]” where you want it to be displayed.
Important
- If you are using the classic editor, use the HTML tab to enter the shortcode.
- In case you are already using the new block editor (Gutenberg) you can add it to the normal paragraph block, the HTML block or the shortcode block. All of them will render the content correctly.
Conclusions
Now you know how to insert a number of entries from another website that is always kept up to date at any point of the website thanks to a shortcode
In addition, you have seen that with small variations you can customize it to suit your needs.
Now you just have to put it into practice. ๐
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. ๐