If you’ve longed for really powerful plugins to help you manipulate your blog content in ways that WordPress doesn’t normally allow, you’ll probably wish you’d known about these 6 free plugins long ago.
Show Content Based On Certain Conditions
Below are 3 plugins that allow you to show or hide content based upon certain conditions. Each is useful in different circumstances.
Optional Content adds a button to the Visual Editor toolbar that allows you to select from a dropdown list of conditions.
Display content within an individual post or page based on the following conditions:
- Manual on/off setting
- До, после, or between specific times (repeated daily)
- До, after or between specific dates
Based on if the visitor is logged in
- Based on a specific user (by user id)
- Based on GET variables (variables passed on the URL in the form of http://www.example.com/about/?test=value where the variable is ‘test’)
- Based on POST variables (variables sent via forms)
- Based on REQUEST variables (either GET or POST variables)
One of many examples might be the need to display a coupon code within a post only if today’s date is between two particular dates, but have it automatically hide that content on all other dates.
Another example might be to show content (like an ad?) only to certain visitors based on whether or not they are logged in, or if they arrived via a particular site or form.
Conditional Shortcodes, like the Optional Content plugin, allows you to show or hide content based upon certain conditions, but the conditions revolve around the where the visitor is viewing the content on the site.
Is the visitor reading this content on the home page? Or is she reading it on a single post? Or maybe she’s looking at a category archive, or some other archive, like a monthly or yearly archive? You decide which content to display on this post, based on where the user is seeing the content, by using fairly easy-to-remember shortcodes around any portion of your content.
Так, например, if you want to only show a Download or Buy Now link if the user is viewing this post as a single post, but not if the user is reading this post on the home page or archive pages, you could use the following shortcode:
[is_single] your link code goes here [/is_single]
If you want different content to be displayed on the home page, и т.п., you could use this instead:
[is_single] your link code goes here [/not_single] See full article to download. [/is_single]
The full list of available shortcodes are:
- is_single – if showing a single post.
- is_singular – if showing a single post or page.
- is_home – if showing the blog home.
- is_front_page – if showing the front page of the site.
- is_sticky – if the current post or page is ‘sticky’.
- is_category – if showing a category-based archive.
- is_tag – if showing a tag-based archive.
- is_tax – if showing a tag- or category-based archive.
- is_author – if showing an author-based archive.
- is_archive – if showing any archive.
- is_year – if showing a yearly archive.
- is_month – if showing a monthly archive.
- is_day – if showing a daily archive.
- is_time – if showing an hourly or shorter archive.
- is_feed – if generating a feed.
- is_search – if showing search results.
- comments_open – if comments are open for the current post or page.
Widget Logic lets you show or hide sidebar widgets based on where the visitor is reading the content. This is similar to the Conditional Shortcodes plugin, however you are able to show or hide sidebar widgets rather than content within a post.
After installing this plugin, if you go to your Widgets area, and drag a widget into any sidebar, you’ll notice a new option that can be set for that widget. So let’s look at a couple of examples.
пример 1. You drag a widget to the sidebar but you only want it to appear if the visitor is currently on the home page. In the Widget Logic option for that widget, you’ll simply type into the form:
пример 2. You drag a widget to the sidebar but you only want it to appear if the visitor is currently on a particular page of the site (let’s say the About page). In the Widget Logic option for that widget, you’ll type:
You can combine conditions, тоже. Например, maybe you only want to display the widget if it is a single post and the post is in the “Cheese” category. Для этого, you’d type:
is_single() && in_category(‘cheese’)
(да, two ampersands is the proper way to signify the word “and”).
Assign Expiration Dates To Some Posts
Post Expirator lets you set an expiration date for a post or page. Once the date has passed, the post will automatically either revert back to Draft status or get deleted completely (your choice).
This is great for posts that are only relevant for a short period of time, such as a post that announces an upcoming event. You could also use it for coupon code posts or anything that you only want displayed on your site until a specified date.
Use PHP Code In Widgets, Posts, And Pages
Samsarin PHP Widget allows you to include PHP code within a text widget.
Normal text widgets don’t let you include PHP code within them. This plugin gives you special text widgets (вплоть до 25 per sidebar) that you can use. You can add PHP to the title of the widget as well as within the body of the widget.
Note that this plugin also comes with an important warning:
Warning: This widget provides great flexibility in customizing your sidebar. It achieves this by automatically evaluating any included PHP included in the title or the body of the widget. Care should be taken when including PHP code in the sidebar, as with anywhere else in the WordPress system.
Placing PHP code within your content has the potential to break things or make your site less secure (depending upon the PHP code you use). Only use this if you’re comfortable with PHP or you completely trust whoever gave you the PHP code to be included. Еще, for those who need to be able to have fine control over widget content, this plugin is awesome.
Allow PHP in Posts and Pages is the same concept as the Samsarin PHP Widget above, except it allows you to use PHP code within your posts and pages, rather than within sidebar widgets.
This plugin lets you use a simple short code to wrap around your PHP code within your posts. пример:
Easy and powerful. Конечно, just like the Samsarin PHP Widget, using PHP code within posts or pages might break things or make your site less secure, so again, only use PHP within your posts and pages if you are very comfortable with PHP, or you completely trust whoever supplied the code to you.
Each of the plugins I’ve mentioned allow you to get really flexible and powerful fine-grain control over your content. Not everyone needs this degree of control, but for those who do, these plugins can be “life-changing”. (Конечно, “life-changing” is probably too dramatic, but for someone who has wished for this kind of content control, it likely “feels” life-changing to find these plugins).
There are other plugins out there that do very similar things, by the way. It’s not like these are the only ones available. Most likely, some of you use others that you might prefer, but these are the ones I’ve used and liked, so that’s why I mention them here. Feel free, тем не мение, to share your preferences for similar plugins in the comments.