From 64c5ea25c22ead3f52e06e94562965abfb70ee12 Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Sun, 20 Nov 2016 13:09:16 +0200 Subject: [PATCH 1/4] blog page as grid --- home.php | 19 ++++++++------ inc/customizer.php | 1 + loop-templates/content-grid.php | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 loop-templates/content-grid.php diff --git a/home.php b/home.php index 9f08b55..f258bc4 100644 --- a/home.php +++ b/home.php @@ -27,9 +27,8 @@ $posts_style = get_theme_mod( 'understrap_posts_index_style' ); - +
-
@@ -39,10 +38,14 @@ $posts_style = get_theme_mod( 'understrap_posts_index_style' ); -
+ - + diff --git a/inc/customizer.php b/inc/customizer.php index 2e1722e..67a167a 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -142,6 +142,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) { 'choices' => array( 'default' => __( 'Default', 'understrap' ), 'masonry' => __( 'Masonry', 'understrap' ), + 'grid' => __( 'Grid', 'understrap' ), ), 'priority' => '30', ) diff --git a/loop-templates/content-grid.php b/loop-templates/content-grid.php new file mode 100644 index 0000000..dbde89d --- /dev/null +++ b/loop-templates/content-grid.php @@ -0,0 +1,44 @@ + + +
+ + +
+ +
id="post-"> + ID ), '_wp_attachment_image_alt', true ); ?> + <?php echo esc_html( $alt ); ?> + +
+ +
+

+ + + + + + + +
+ +
+ +
+ + +
+ + +
+
From 77ca414da60bd70fbd7be5da09ea19a83e83f40c Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Mon, 21 Nov 2016 11:54:27 +0200 Subject: [PATCH 2/4] add option for column settings --- inc/customizer.php | 44 +++++++++++++++++++++++++++++++++ loop-templates/content-grid.php | 5 ++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index 67a167a..9e8b035 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -147,6 +147,50 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) { 'priority' => '30', ) ) ); + + // Columns setup for grid posts. + /** + * Function and callback to check when grid is enabled. + * @return bool + */ + function is_grid_enabled () + { + return 'grid' == get_theme_mod( 'understrap_posts_index_style' ); + } + if ( is_grid_enabled() ) { + // How many columns to use each grid post + $wp_customize->add_setting( 'understrap_grid_post_columns', array( + 'default' => '6', + 'type' => 'theme_mod', + 'capability' => 'edit_theme_options', + 'transport' => 'refresh', + ) ); + + $wp_customize->add_control( + new WP_Customize_Control( + $wp_customize, + 'understrap_grid_post_columns', array( + 'label' => __( 'Grid Post Columns', 'understrap' ), + 'description' => __( "Choose how many columns to use in grid posts", 'understrap' ), + 'section' => 'understrap_theme_layout_options', + 'settings' => 'understrap_grid_post_columns', + 'type' => 'select', + 'choices' => array( + '6' => '6', + '4' => '4', + '3' => '3', + '2' => '2', + '1' => '1', + ), + 'default' => 6, + 'priority' => '30', + 'transport' => 'refresh', + ) + ) ); + + } + // hook to auto-hide/show depending the understrap_posts_index_style option + $wp_customize->get_control( 'understrap_grid_post_columns' )->active_callback = 'is_grid_enabled'; } } add_action( 'customize_register', 'understrap_theme_customize_register' ); diff --git a/loop-templates/content-grid.php b/loop-templates/content-grid.php index dbde89d..223e520 100644 --- a/loop-templates/content-grid.php +++ b/loop-templates/content-grid.php @@ -4,10 +4,11 @@ * * @package understrap */ - +$col = get_theme_mod( 'understrap_grid_post_columns' ); +error_log($col); ?> -
+
From 65b7d230cf1c9510fef8348ce6df2f01d6878eab Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Mon, 21 Nov 2016 11:56:20 +0200 Subject: [PATCH 3/4] remove debug log --- loop-templates/content-grid.php | 1 - 1 file changed, 1 deletion(-) diff --git a/loop-templates/content-grid.php b/loop-templates/content-grid.php index 223e520..4e2885e 100644 --- a/loop-templates/content-grid.php +++ b/loop-templates/content-grid.php @@ -5,7 +5,6 @@ * @package understrap */ $col = get_theme_mod( 'understrap_grid_post_columns' ); -error_log($col); ?>
From 018e930d44976efbc328da17a914c9046328c6dc Mon Sep 17 00:00:00 2001 From: koenemann Date: Mon, 21 Nov 2016 11:41:29 +0100 Subject: [PATCH 4/4] Revers to old gallery because add_shortcode is not allowed --- inc/bootstrap-wp-gallery.php | 196 ++++++++++++++++++++--------------- 1 file changed, 110 insertions(+), 86 deletions(-) diff --git a/inc/bootstrap-wp-gallery.php b/inc/bootstrap-wp-gallery.php index 6ccc70c..1a471a2 100644 --- a/inc/bootstrap-wp-gallery.php +++ b/inc/bootstrap-wp-gallery.php @@ -1,105 +1,129 @@ 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, - 'itemtag' => '', - 'icontag' => '', - 'captiontag' => '', + 'itemtag' => 'div', + 'icontag' => 'div', + 'captiontag' => 'div', 'columns' => 3, 'size' => 'thumbnail', - 'include' => '', - 'exclude' => '', - 'link' => '' - ], $attr)); - $id = intval($id); - $columns = (12 % $columns == 0) ? $columns : 3; - $grid = sprintf('col-sm-%1$s col-lg-%1$s', 12 / $columns); - if ($order === 'RAND') { - $orderby = 'none'; - } - if (!empty($include)) { - $_attachments = get_posts(['include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); - $attachments = []; - foreach ($_attachments as $key => $val) { - $attachments[$val->ID] = $_attachments[$key]; + 'exclude' => '' + ), $attr ) ); + + // Initialize + $id = intval( $id ); + $attachments = array(); + if ( $order == 'RAND' ) $orderby = 'none'; + + + if ( ! empty( $include ) ) { + + // Include attribute is present + $include = preg_replace( '/[^0-9,]+/', '', $include ); + $_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); + + // Setup attachments array + foreach ( $_attachments as $key => $val ) { + $attachments[ $val->ID ] = $_attachments[ $key ]; } - } elseif (!empty($exclude)) { - $attachments = get_children(['post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); + + } else if ( ! empty( $exclude ) ) { + + // Exclude attribute is present + $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); + + // Setup attachments array + $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } else { - $attachments = get_children(['post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); + // Setup attachments array + $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } - if (empty($attachments)) { - return ''; - } - if (is_feed()) { + + if ( empty( $attachments ) ) return ''; + + // Filter gallery differently for feeds + if ( is_feed() ) { $output = "\n"; - foreach ($attachments as $att_id => $attachment) { - $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; - } + foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n"; return $output; } - $unique = (get_query_var('page')) ? $instance . '-p' . get_query_var('page') : $instance; - $output = '' : ''; - $output .= '
'; - return $output; -} -add_shortcode('gallery', 'shortcode_gallery'); -/** - * Add class="thumbnail img-thumbnail" to attachment items - */ -function attachment_link_class($html) { - $html = str_replace(' 0 ? floor( 12 / $columns ) : 100; + $float = is_rtl() ? 'right' : 'left'; + $selector = "gallery-{$instance}"; + + // Filter gallery CSS + $output = apply_filters( 'gallery_style', " + + \n"; + + return $output; + } -add_filter('wp_get_attachment_link', 'attachment_link_class', 10, 1); + +// Apply filter to default gallery shortcode +add_filter( 'post_gallery', 'bootstrap_wp_gallery', 10, 2 );