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.