20+
April 22, 2013
April 2, 2013
Gridster is a WordPress plugin that makes building intuitive draggable layouts from elements spanning multiple columns. You can even dynamically resize, add and remove elements from the grid, as edit the elements content inline.
You can fork Gridster at Github or tell me about your issues.
Adjust the HTML output of the gridster-widgets by overriding the default template from cbach-wp-gridster/views/gridster-default.php.
Just copy this file into a new created directory gridster-templates within your theme folder and change it to your needs.
Furthermore you can add different templates per post_type, when you create files like gridster-YOUR_POST_TYPE_NAME.php within these folder.
By using the later described gridster_locate_templates_from filter you are able to add more conditions to make your templates match more customized conditions.
With help of the Jeditable library it is possible to edit loaded content directly inside the gridster workbench.
So if you are using a post called “My grandmothers apple pie is the best”, you could adjust the text inside your gridster-widget to shorter version, ie. “best apple pie” without editing the original post.
Just add some CSS class to the wrapper element, where your title will appear.
For editing single lines of text, like titles add class="gridster_edit".
If you want to edit texts in more comfortable textarea use class="gridster_edit-area"
Have a look at the /views/gridster-default.php inside the plugin directory to get a clue.
You can adjust the behavior of this plugin by using following filters:
get_post_types() call for usable post_types by filtering gridster_get_post_types_as_widget_blocks_argsgridster_post_types_as_widget_blocksgridster_get_posts_by_type_query_argsgridster_locate_templates_fromgridster_choose_from_custom_css_classes_for_widgets filter.array( 'alignleft' => __('Align text from left'), 'alignright' => __('Align text from right'), where the array_keys are the CSS classes to apply and the values are the readable text for you or your editors.gridster_overwrite_post_options_with_cap. By default “edit_theme_options” is used.Or you can hook in your own functionality by using the following action hooks:
gridster_before_shortcode_render or gridster_after_shortcode_render. Both action hooks come with three additional arguments you are able to work with, the $post_id, the $title and the $widgets_html of the current gridster-post. Have a look inside the plugin file to see, what variables you are able to use within your filter hooks.
<select>s more user-friendlywp-content/plugins/ directory of your WordPress installationThere a some CSS classes you can use
.gridster-not-loaded is appended to the <body> element, when a shortcode is found on the current page.gridster-loaded replaces the former mentioned .gridster-not-loaded body-class, when Gridster Javascript is successfully loaded.gridster-wrap is the wrapper for the whole shortcode output.gs_w is the generic class aplied to every Gridster WidgetThe Plugin comes with minimal styling for the Gridster Markup, but maybe you’ll add theese few lines of CSS to your own theme stylesheet to reduce server requests.
Just set the constant GRIDSTER_FRONTEND_CSS to false in your themes functions.php file.
/**
* Do not use gridster frontend styles
*/
define( 'GRIDSTER_FRONTEND_CSS', false );
Gridster uses the generated images used as post-thumbnails by default. When you add existing content to a new gridster, the plugin will look for the best fitting image size, according to the width and height of your current gridster-widget.
So if you have defined the base width to 100px, base height to 100px and your margins to 10px, the plugin will look for images of 100 * 100 px.
Now, when you resize this gridster-widget to, let’s say, 1 row with 2 columns, the plugin will reload this gridster-widget with an image of 220 * 100 px.
To avoid ugly cropping or unwanted scaling of the post-thumbnails, you go best with defining some additional post-thumbnail sizes within your functions.php like so.
/**
* Add some additional post-thumbnail sizes, that can be used by the Gridster Plugin
* e.g. we have base-width: 100px, base-height: 100px and margins both 10px
*
* @see https://codex.wordpress.org/Function_Reference/add_image_size
*
*/
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'gridster-1col-1row', 100, 100, true );
add_image_size( 'gridster-2col-1row', 220, 100, true );
add_image_size( 'gridster-3col-1row', 340, 100, true );
add_image_size( 'gridster-4col-1row', 460, 100, true );
add_image_size( 'gridster-1col-2row', 100, 220, true );
add_image_size( 'gridster-1col-3row', 100, 340, true );
add_image_size( 'gridster-1col-4row', 100, 460, true );
/** ... and so on ... */
}
Drop me a line at gridster@carsten-bach.de
shortcode_atts_{shortcode}-filter, introduced in WP 3.6; use it like this add_filter( 'shortcode_atts_gridster', 'YOUR-FILTER-FUNCTION-NAME' );add_filter( 'gridster_shortcode_output', 'YOUR-FILTER-FUNCTION-NAME' )Undefined Property $widget->classes on line 2191gridster_overwrite_post_options_with_cap to define capability, which allows users to overwrite defaull layout settings for each gridster individually<body>, .gridster-not-loaded when shortode is used as a Noscript fallback and .gridster-loaded when JS is available and the Layout is loaded properly.gridster_edit-areagridster_choose_from_custom_css_classes_for_widgets filter and is not used by default