I’ve had a look at many of the available plugins but they all seem to be too difficult to use or do not provide enough flexibility.
Plugins I’ve already tried:
- WP Post Columns
- Magazine Columns
- WP Columns
- WP Easy Columns
I’ve also look at one that allowed for per-page sidebars which could work but the column is separate for the content making it difficult to manage, and the lack of a WYSIWYG editor makes it difficult for those not familiar with HTML.
What I’m Trying Achieve:
The project I’m working on requires that the people responsible for entering the content be able to add content to a 3/4 column that is the main content and a 1/4 column that is informational content relating to the main content. The content of the 1/4 column will change depending on the page.
To most developers, it’s simple to write HTML to do that in the post’s content but the people that will be adding/modifying the content don’t know HTML so I’m looking for alternatives. I would prefer if they didn’t have to remember codes (or short codes).
To complicate things, I have 3 templates: “1 column”, “2 columns (1/4, 3/4)” and “2 columns (3/4, 1/4)”.
The Question:
Has anyone come up with a simple solution to this problem? Is there a plugin that I’m not aware of that would add the ability to have multiple content (column) for a single page? Or is there something that would allow me to add a WYSIWYG editor to widgets?
I look forward to your thoughts and recommendations.
Here is an interesting approach:
THE PLAN AND LOGIC:
Custom fields are a build in functionality that will fit our needs perfectly. We can set a new custom field and then use that field to enter and store our custom data. We can then use a widget to display this custom content in the sidebar of our single pages
Example of custom field in post editor
Possible issues:
There are a few issues we need to take into account
Whether or not a widget has content or not, it counts as an active sidebar. The issue is, we do not want to display the widget on any other page that the single post page, also, we would want to hide the sidebar when we do not have any other widgets and when our custom widget is empty. There is no build in function to set the
is_active_sidebar()
conditional statement to false, or have any similar function to hide a sidebar when we have a sidebar with an empty widget onlySome themes do not have the ability to switch between full width mode and normal mode with sidebar when the status of a sidebar changes from active to inactive and vice versa
SOLUTIONS TO OUR MAIN ISSUE:
Our main issue is how to hide the widget when it is empty or if we are on a page that is not a single post page. Our plan here would be remove the custom widget from the array of sidebars widgets returned via the
wp_get_sidebars_widgets()
function. We specially make use of the build in filtersidebars_widgets
.It is really straight forward to determine the page we are on by simply using the
is_single()
conditional statement.As to how to determine if our widget is empty or not, the logic is quite simple. We will need a helper function to get the post meta value from our custom filed on single post pages. This helper function will be used by our widget to display the content. Now, this logic can be used to determine if our widget will be empty or not, and according to this, we can hide/remove the widget from the
wp_get_sidebars_widgets()
which is used by functions likeis_active_sidebar()
The issue regarding full width vs normal display according to the status of a sidebar is quite easy, and I’m not going to go into this right here. In short though, if you look at the twentyfourteen theme, it uses
body_class
es to set a CSS class offull-width
when the content sidebar (sidebar-2
) is empty. This means that the content area is set to 100% width (if you want to call it that) to hide the blank space on the right of the content if there are no widgets in the sidebar.Here is the section responsible for this
You can, in your own time, have a look at the CSS that is used to switch between full width and normal view with a sidebar, and be sure to play around with the possibilities
THE CODE:
HELPER FUNCTION
get_custom_field_content
We will first write our helper function to return the custom content from the custom field from the post in single view. I have commented the code, so it will be easy to follow
This function will be used in our widget to get the custom content and then display it. The
$key
parameter in the function will be the custom field name, in our example, that will becustom_content
. This function will also be used by our filter function to determine if our widget is empty and to remove our widget from our sidebars on a conditional statementTHE WIDGET:
This our widget, which will have a field where you should enter the custom field name in the specified field. Again, the code is commented to make it easy to follow
This is how our widget will look like in back end
FILTER FUNCTION:
Lastly is our helper function to remove the widget on all pages except single post pages and whenever the widget is empty. Again, the code is commented to make it easy to follow
And that is all we need. Using the twentyfourteen theme, this is what you will see if we have custom content
and here is a post without custom content
EDIT- this answer is old, there are better options.
a few plugins – pods, magic fields, custom fields template.
or you can DIY with some meta boxes and tinymce editors, see this answer.
This is something I would handle at the theme template level. You mention that the person entering in the content needs to do both so I presume the writer is entering both on the same post.
On the back-end, I would install the plugin Advanced Custom Fields. This is just to save you the headache of trying to add a WYSIWYG custom field option for the sidebar. It is relatively straight forward process to create this and even allows some rules that make it highly customized.
In the content.php template file for this post type you would use the following code:
What this code will do within the article tag, since you state its content is directly related to the main content, is create an aside within the article, go into the _postmeta table with the current post’s ID and lookup the key ‘sidebar_content’ (This is a name that you will give the field in ACF).
The requirement is unclear: Must content editors create new columns ONLY within the post content? Or is it OK to use the post content as their 3/4 column and then they can edit a sidebar widget which will create the 1/4 column?
If it is the latter — which you asked at the end with “Is there something that would allow me to add a WYSIWYG editor to widgets?” — then the answer is simple: just install WYSIWYG editor widget(s) in your sidebar and have your people edit content there. WP Editor Widget looks like a well-supported plugin that does just that.