This is great! Thanks Simon. Been looking for a way to embed a few latest posts in Wordpress.
Our use case for this: weāre building a membership site and would like to have a list on our main member dashboard that links to a few Discourse discussions members would be most likely to enjoy.
One suggestion: it might be useful to have a [discourse_top] shortcode that works basically the same way as [discourse_latest]. I imagine it would take same params + a ārangeā option to specify ātodayā / āweekā / āmonthā / etc.
Iām thinking ātopā topics might be more likely to spark engagement than ānewestā. Though may be cool to display both, actually
PS ā just saw your new āWP Discourse Latest Topicsā plugin linked in the WP Discourse 1.2.5 announcement. It seems thatās basically a single feature extracted from this shortcodes plugin, as a demo/test of some sort? For using [discourse_latest] should we stick to using the shortcodes plugin for now?
They are both officially āWorks in Progressā. My intention is to rework the wp-discourse-shortcodes plugin by gradually adding shortcodes to it - starting with [discourse_latest]. If anyone wants to use this on a production site, they should get in touch with me.
Iām not sure, I can take a look at it. I havenāt done any work on this plugin for quite a while.
Iāve developed a separate plugin for the latest_topics shortcode that allows you to use a Discourse webhook so that topics are updated in real time. That plugin is also going to include a discourse_top shortcode. I need to double-check my work on it. Once Iāve done that Iāll post a link to the code.
@simon I know you have not worked on this in awhile but was wondering if you could help me with an issue with the groups function. If i have an ā@ā mention within the description for the group the link is incorrect on my wordpress site. I believe it has to do with the way the link is formatted within Discourse in that it does not include the domain name. When it displays the mention in wordpress it grabs the WordPress site domain instead. Is there a way to rewrite the link so that it has my Discourse domain instead?
Also the invite group buttons donāt show up which i think my be a theme issue for me.
Iāve made a new plugin for displaying the latest topics. It uses a webhook for refreshing the topics. Iāve been wondering about moving the groups shortcode into that one. Iāll look at it today.
There are a couple of problems with the current version of this plugin when using the latest Discourse version. Since Discourse has added /groups pages and a group description field, it makes sense to update the plugin to use those.
Hereās a new version of the plugin. It ties into the WP Discourse settings page. For the group links, it defaults to linking to the /groups/group-name page. Thereās an option to send a message to the group if you want the old behaviour. It gets the group_description from the group_description field, instead of requiring you to create a topic for it.
There are no styles added to the displayed groups.
It adds a new version of the latest_topics shortcode that can be updated with a webhook.
This isnāt quite ready to be used, but feel free to try it out and let me know if you run into any problems. Iāll try to get back to it later this week. Iām going to add a discourse_top shortcode and a staged_user option to the discourse_prefilled_message shortcode.
Loaded this up and went through it a bit. Works well. I did notice that if there is an image in the description the image does not show up on the WordPress site. Instead it just shows the link to the image.
Thatās strange, a description like this one displays correctly in my development setup:
<img src="http://localhost:3000/uploads/default/original/1X/e2395d972cefce63ff99f8b9bc8c3973a6b8e7c3.jpg" />
<p>Walking in and around Nanaimo.</p>
If you change the group description, you need to select the Refresh Discourse Groups checkbox on the Shortcodes tab. It is only enabled for a single request. The UI for this isnāt very clear, but it seems like the most efficient way to do it.
Iāve done some work on the discourse_latest shortcode. Itās now called discourse_topics. You can specify which topic list you want with a shortcode attribute. It currently has /latest and /top(daily|monthly|quarterly...) routes. Iāll add a categories route soon. An excerpt can be added to each topic by giving a value to the excerpt_length attribute. If you give it the value āfullā, it will display the full posts. The data and assembled HTML is cached. You can specify the cache_duration for each shortcode. An optional webhook can be used to break the cache for the /latest route. Thereās an option for updating the latest route with ajax.
The position of the category badge, avatar, username, and date can all be set with shortcode attributes. A category class is added to each list item that can be used for styling. The plugin comes with some optional styles. If they are used, adding a tile=true attribute to the shortcode gives a basic tile layout. The size and spacing of the tiles can be altered by adding some css. Overflowing text in the tiles is truncated with javascript.
Iāve also added an RSS shortcode that does basically the same thing, but displays less information. Iām not sure that itās going to make it into the final version of the plugin.
The code is here https://github.com/scossar/wp-discourse-shortcodes. Thereās a messy live demo here https://testeleven.com/. Iāll be working on it some more this week, and also writing some documentation. If anyone would like to try it out in the meantime, bug reports would be greatly appreciated.