Browse Source

Reduce blocks to four; move front page catalog to customizer.

pull/9/head
Ned Zimmerman 7 years ago
parent
commit
98c4f8dee1
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 18
      app/admin.php
  2. 4
      app/setup.php
  3. 2
      app/widgets.php
  4. 106
      app/widgets/latestbooks.php
  5. 1
      resources/functions.php
  6. 31
      resources/views/front-page.blade.php

18
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',
]);
});
/**

4
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'

2
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');
});

106
app/widgets/latestbooks.php

@ -1,106 +0,0 @@
<?php
namespace Aldine;
class LatestBooks extends \WP_Widget
{
/**
* Constructor.
*
* @see WP_Widget::__construct()
*
*/
public function __construct()
{
parent::__construct('latestbooks', __('Latest Books', 'aldine'), [
'description' => esc_html__('Your network&#8217;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 '<div class="books">';
for ($i = 0; $i < $number; $i++) {
printf(
'<div class="book">
<a class="subject" href="">TK</a>
<a class="title" href="%1$s">%2$s</a>
<a class="read-more" href="%1$s">%3$s</a>
</div>',
$books[$i]['link'],
$books[$i]['metadata']['name'],
__('About this book &rarr;', 'aldine')
);
}
echo '</div>';
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; ?>
<p><label for="<?= $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input
class="widefat"
id="<?= $this->get_field_id('title'); ?>"
name="<?= $this->get_field_name('title'); ?>"
type="text"
value="<?= $title; ?>" /></p>
<p><label for="<?= $this->get_field_id('number'); ?>"><?php _e('Number of books to show:'); ?></label>
<input
class="tiny-text"
id="<?= $this->get_field_id('number'); ?>"
name="<?= $this->get_field_name('number'); ?>"
type="number"
step="1"
min="1"
value="<?= $number; ?>"
size="3" /></p>
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update($new_instance, $old_instance)
{
$instance = [];
$instance['title'] = ( ! empty($new_instance['title']) ) ? strip_tags($new_instance['title']) : '';
$instance['number'] = (int) $new_instance['number'];
return $instance;
}
}

1
resources/functions.php

@ -67,7 +67,6 @@ array_map(function ($file) use ($sage_error) {
'filters',
'admin',
'widgets',
'widgets/latestbooks',
'widgets/linkbutton',
'widgets/pagebutton'
]);

31
resources/views/front-page.blade.php

@ -4,11 +4,11 @@
@if($block_count === 0)
<div class="block block-1">
<div class="inside">
<h3>{{ __('About Pressbooks', 'aldine')}}</h3>
<h3>{{ __('About Pressbooks', 'aldine') }}</h3>
<p>{{ __('Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'aldine')}}</p>
</div>
</div>
@elseif($block_count < 5)
@elseif($block_count < 4)
@for($i = 0; $i < $block_count; $i++)
<div class="block block-{{ $i + 1 }}@if($latest_books_block === $home_blocks[$i]) latest-books @endif">
<div class="inside">
@ -16,7 +16,7 @@
</div>
</div>
@endfor
@elseif($block_count === 5)
@elseif($block_count === 4)
<div class="one-two">
@for($i = 0; $i < 2; $i++)
<div class="block block-{{ $i + 1 }}@if($latest_books_block === $home_blocks[$i]) latest-books @endif">
@ -34,4 +34,29 @@
</div>
@endfor
@endif
@if(get_theme_mod('pb_front_page_catalog'))
<div class="block latest-books">
<div class="inside">
<h3>{{ get_theme_mod('pb_front_page_catalog_title') }}</h3>
@php
$books = wp_remote_get(home_url('/wp-json/pressbooks/v2/books'));
$books = json_decode($books['body'], true);
echo '<div class="books">';
for ($i = 0; $i < 3; $i++) {
printf(
'<div class="book">
<a class="subject" href="">TK</a>
<a class="title" href="%1$s">%2$s</a>
<a class="read-more" href="%1$s">%3$s</a>
</div>',
$books[$i]['link'],
$books[$i]['metadata']['name'],
__('About this book &rarr;', 'aldine')
);
}
echo '</div>';
@endphp
</div>
</div>
@endif
@endsection

Loading…
Cancel
Save