Dynamic Content Widget
A Swiss Army Knife for WordPress developers. With this WordPress widget, you can enter a slug or id, select a template part, and the widget will render content with your HTML.
Very handy for things like:
- Pinning content (pages and posts) to the homepage.
- Rendering arbitrary content (pages and posts) in a sidebar or other widget area.
- Many more uses.
Very simple, but also very powerful and versatile. Also may be difficult to use for people who are not into template hacking, so if you don’t know php, this widget isn’t for you.
Download
Download the plugin here, or go to plugins->Add New, search ‘dynamic content widget‘, by Dikhoff Software.
Instructions:
- Install and activate the plugin by going to plugins->Add New, search ‘dynamic content widget‘, by Dikhoff Software.
- Create a new file in your theme directory, call it ‘dynamic-content-example.php‘, and paste this code in it:
[php]
post_type == ‘page’) {
?>
Page
Blog
[/php] - Go to the widgets menu in WordPress and add the Dynamic Content Widget to the area you want.
You’ll see this:
Title is the same as other widgets, I usually leave it empty. Slug or id is the identifier of the page or post you want your template applied to. The slug is the last part of the url of the page or post. For subtemplate, choose ‘Dynamic content example’ (that’s the file you created earlier).
Learn how you can use Dynamic Content Widget by reading these use cases:
Save the widget and look at the result. You now have an easy way to render arbitrary content in a widget area, while retaining complete control over the HTML. Play with dynamic-content-example.php to try out the possibilities.
If you want to create your own templates, the important thing to remember is that this widget will only ‘see’ templates that have the string: “Subtemplate: [name]” in it. This is different from normal templates, which use the string: “Template name: [name]” for identification. This may be confusing but it’s to avoid mixing page templates with subtemplates.
This widget should also work for custom content types by the way, but you probably have to use id’s instead of slugs in those cases.
A better version of this Widget will be a part of the WordPress plugin that I’m working on.