From 98c4f8dee1bc6b3527c561c4264c6e0885ff8c7e Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Sat, 26 Aug 2017 14:11:23 -0300 Subject: [PATCH] Reduce blocks to four; move front page catalog to customizer. --- app/admin.php | 18 +++++ app/setup.php | 4 - app/widgets.php | 2 +- app/widgets/latestbooks.php | 106 --------------------------- resources/functions.php | 1 - resources/views/front-page.blade.php | 31 +++++++- 6 files changed, 47 insertions(+), 115 deletions(-) delete mode 100644 app/widgets/latestbooks.php diff --git a/app/admin.php b/app/admin.php index 4e3bc20..9e9c921 100644 --- a/app/admin.php +++ b/app/admin.php @@ -34,6 +34,24 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize) 'section' => 'pb_network_social', 'settings' => 'pb_network_twitter', ]); + $wp_customize->add_section('pb_network_catalog', [ + 'title' => __('Catalog', 'aldine'), + 'priority' => 20, + ]); + $wp_customize->add_setting('pb_front_page_catalog'); + $wp_customize->add_control('pb_front_page_catalog', [ + 'label' => __('Show Front Page Catalog', 'aldine'), + 'section' => 'pb_network_catalog', + 'settings' => 'pb_front_page_catalog', + 'type' => 'checkbox' + ]); + $wp_customize->add_setting('pb_front_pa ge_catalog_title'); + $wp_customize->add_control('pb_front_page_catalog_title', [ + 'label' => __('Front Page Catalog Title', 'aldine'), + 'section' => 'pb_network_catalog', + 'settings' => 'pb_front_page_catalog_title', + ]); + }); /** diff --git a/app/setup.php b/app/setup.php index b44dcfc..fe5a4e9 100644 --- a/app/setup.php +++ b/app/setup.php @@ -122,10 +122,6 @@ add_action('widgets_init', function () { 'name' => __('Home Block 4', 'aldine'), 'id' => 'home-block-4' ] + $config); - register_sidebar([ - 'name' => __('Home Block 5', 'aldine'), - 'id' => 'home-block-5' - ] + $config); register_sidebar([ 'name' => __('Network Footer Block 1', 'aldine'), 'id' => 'network-footer-block-1' diff --git a/app/widgets.php b/app/widgets.php index 1daaf00..6aa9667 100644 --- a/app/widgets.php +++ b/app/widgets.php @@ -14,11 +14,11 @@ add_action('widgets_init', function () { 'WP_Widget_Categories', 'WP_Widget_Recent_Posts', 'WP_Widget_Recent_Comments', + 'WP_Widget_RSS', 'WP_Widget_Tag_Cloud' ] as $widget) { unregister_widget($widget); } - register_widget('Aldine\LatestBooks'); register_widget('Aldine\LinkButton'); register_widget('Aldine\PageButton'); }); diff --git a/app/widgets/latestbooks.php b/app/widgets/latestbooks.php deleted file mode 100644 index 04ff454..0000000 --- a/app/widgets/latestbooks.php +++ /dev/null @@ -1,106 +0,0 @@ - esc_html__('Your network’s latest books.', 'aldine') - ]); - } - - /** - * Front-end display of widget. - * - * @see WP_Widget::widget() - * - * @param array $args Widget arguments. - * @param array $instance Saved values from database. - */ - public function widget($args, $instance) - { - $number = (! empty($instance['number'])) ? absint($instance['number']) : 3; - if (!$number) { - $number = 3; - } - if (empty($instance['title'])) { - $instance['title'] = __('Latest Books', 'aldine'); - } - echo $args['before_widget']; - echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; - $books = wp_remote_get(home_url('/wp-json/pressbooks/v2/books')); - $books = json_decode($books['body'], true); - echo '
'; - for ($i = 0; $i < $number; $i++) { - printf( - '
- TK - %2$s - %3$s -
', - $books[$i]['link'], - $books[$i]['metadata']['name'], - __('About this book →', 'aldine') - ); - } - echo '
'; - echo $args['after_widget']; - } - - /** - * Back-end widget form. - * - * @see WP_Widget::form() - * - * @param array $instance Previously saved values from database. - */ - public function form($instance) - { - $title = ! empty($instance['title']) ? $instance['title'] : ''; - $number = ! empty($instance['number']) ? absint($instance['number']) : 3; ?> -

-

-

-

-
-

{{ __('About Pressbooks', 'aldine')}}

+

{{ __('About Pressbooks', 'aldine') }}

{{ __('Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'aldine')}}

- @elseif($block_count < 5) + @elseif($block_count < 4) @for($i = 0; $i < $block_count; $i++)
@@ -16,7 +16,7 @@
@endfor - @elseif($block_count === 5) + @elseif($block_count === 4)
@for($i = 0; $i < 2; $i++)
@@ -34,4 +34,29 @@
@endfor @endif + @if(get_theme_mod('pb_front_page_catalog')) +
+
+

{{ get_theme_mod('pb_front_page_catalog_title') }}

+ @php + $books = wp_remote_get(home_url('/wp-json/pressbooks/v2/books')); + $books = json_decode($books['body'], true); + echo '
'; + for ($i = 0; $i < 3; $i++) { + printf( + '
+ TK + %2$s + %3$s +
', + $books[$i]['link'], + $books[$i]['metadata']['name'], + __('About this book →', 'aldine') + ); + } + echo '
'; + @endphp +
+
+ @endif @endsection