0

Are widgets meant to be used outside of sidebars?

My case: I have this html block which I want to use every time I display a post with category of "Story". I was going to make a widget to reduce duplicate code. Is there a better way to apply this html block to every displaying of a "Story" post?

4 Answers 4

1

If the category is Story, then make a template file, and name it as category-story.php (make sure the slug is 'story'). Put your code in this file. WordPress will automatically display the posts from Story category using this template. (More about category templates here). And yes, you can use widgets outside of the sidebar, read how.

1

I frequently use widgets outside sidebars. It's a fantastic way to make editing content in WordPress easier, however in your situation you may wish to use a file named 'category-story.php' or use the is_category() conditional tag to display content when a given category is viewed.

1

Widgets are just placeholders with enhanced functionality. I build a plugin once to add widgets to the head and footer sections of an HTML document.
I’d say it depends on your needs: If you need some configuration use a widget. Otherwise shortcodes or special templates may do the same job.

1

Yes, one common use is the Widgetized Footer. The typical ones enable one to put three or four columns in the footer which you populate via widgets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.