Browse Source

Replace widget areas with content blocks; add custom widget area.

pull/11/head
Ned Zimmerman 7 years ago
parent
commit
633eaa75f0
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 56
      app/admin.php
  2. 37
      app/controllers/FrontPage.php
  3. 16
      app/setup.php
  4. 69
      resources/views/front-page.blade.php
  5. 11
      resources/views/partials/front-page-block.blade.php

56
app/admin.php

@ -36,23 +36,69 @@ 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'),
$wp_customize->add_section('pb_front_page_content', [
'title' => __('Front Page Content', 'aldine'),
'priority' => 20,
]);
$wp_customize->add_setting('pb_front_page_catalog');
for($i = 1; $i < 5; $i++) {
$wp_customize->add_setting("pb_front_page_block_${i}_title", [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field',
]);
$wp_customize->add_control("pb_front_page_block_${i}_title", [
'label' => sprintf(__('Block %d Title', 'aldine'), $i),
'section' => 'pb_front_page_content',
'settings' => "pb_front_page_block_${i}_title",
]);
$wp_customize->add_setting("pb_front_page_block_${i}_content", [
'type' => 'option',
'sanitize_callback' => 'sanitize_textarea_field',
]);
$wp_customize->add_control("pb_front_page_block_${i}_content", [
'label' => sprintf(__('Block %d Content', 'aldine'), $i),
'type' => 'textarea',
'section' => 'pb_front_page_content',
'settings' => "pb_front_page_block_${i}_content",
]);
$wp_customize->add_setting("pb_front_page_block_${i}_button_title", [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field',
]);
$wp_customize->add_control("pb_front_page_block_${i}_button_title", [
'label' => sprintf(__('Block %d Button Title', 'aldine'), $i),
'section' => 'pb_front_page_content',
'settings' => "pb_front_page_block_${i}_button_title",
]);
$wp_customize->add_setting("pb_front_page_block_${i}_button_url", [
'type' => 'option',
'sanitize_callback' => 'esc_url_raw',
]);
$wp_customize->add_control("pb_front_page_block_${i}_button_url", [
'label' => sprintf(__('Block %d Button URL', 'aldine'), $i),
'section' => 'pb_front_page_content',
'settings' => "pb_front_page_block_${i}_button_url",
]);
}
$wp_customize->add_section('pb_front_page_catalog', [
'title' => __('Front Page Catalog', 'aldine'),
'priority' => 25,
]);
$wp_customize->add_setting('pb_front_page_catalog', [
'type' => 'option',
]);
$wp_customize->add_control('pb_front_page_catalog', [
'label' => __('Show Front Page Catalog', 'aldine'),
'section' => 'pb_network_catalog',
'section' => 'pb_front_page_catalog',
'settings' => 'pb_front_page_catalog',
'type' => 'checkbox'
]);
$wp_customize->add_setting('pb_front_page_catalog_title', [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field'
]);
$wp_customize->add_control('pb_front_page_catalog_title', [
'label' => __('Front Page Catalog Title', 'aldine'),
'section' => 'pb_network_catalog',
'section' => 'pb_front_page_catalog',
'settings' => 'pb_front_page_catalog_title',
]);
});

37
app/controllers/FrontPage.php

@ -9,13 +9,8 @@ class FrontPage extends Controller
public function blockCount()
{
$c = 0;
foreach ([
'home-block-1',
'home-block-2',
'home-block-3',
'home-block-4'
] as $block) {
if (is_active_sidebar($block)) {
for ($i = 1; $i < 5; $i++) {
if (get_option("pb_front_page_block_${i}_content")) {
$c++;
}
}
@ -25,10 +20,23 @@ class FrontPage extends Controller
public function blocks()
{
$blocks = [];
for ($i = 0; $i < 4; $i++) {
if (is_active_sidebar("home-block-$i")) {
$blocks[] = "home-block-$i";
for ($i = 1; $i < 5; $i++) {
$block = [];
$title = get_option("pb_front_page_block_${i}_title");
$content = get_option("pb_front_page_block_${i}_content");
$button_title = get_option("pb_front_page_block_${i}_button_title");
$button_url = get_option("pb_front_page_block_${i}_button_url");
if ($title) {
$block['title'] = $title;
}
if ($content) {
$block['content'] = wpautop($content);
}
if ($button_title && $button_url) {
$block['button_title'] = $button_title;
$block['button_url'] = $button_url;
}
$blocks[] = $block;
}
return $blocks;
@ -57,9 +65,12 @@ class FrontPage extends Controller
public function latestBooksTitle()
{
return (empty(get_theme_mod('pb_front_page_catalog_title'))) ?
__('Our Latest Titles', 'aldine') :
get_theme_mod('pb_front_page_catalog_title');
$title = get_option('pb_front_page_catalog_title');
if ($title) {
return $title;
}
return __('Our Latest Titles', 'aldine');
}
public static function latestBooks($page = 1, $per_page = 3)

16
app/setup.php

@ -108,20 +108,8 @@ add_action('widgets_init', function () {
'after_title' => '</h3>'
];
register_sidebar([
'name' => __('Home Block 1', 'aldine'),
'id' => 'home-block-1'
] + $config);
register_sidebar([
'name' => __('Home Block 2', 'aldine'),
'id' => 'home-block-2'
] + $config);
register_sidebar([
'name' => __('Home Block 3', 'aldine'),
'id' => 'home-block-3'
] + $config);
register_sidebar([
'name' => __('Home Block 4', 'aldine'),
'id' => 'home-block-4'
'name' => __('Front Page Content', 'aldine'),
'id' => 'front-page-block'
] + $config);
register_sidebar([
'name' => __('Network Footer Block 1', 'aldine'),

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

@ -2,39 +2,60 @@
@section('content')
@if($block_count === 0)
<div class="block block-1 flex flex-column items-center justify-center p-0 w-100">
<div class="inside">
<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>
@component('partials.front-page-block', ['index' => 1])
@slot('title')
{{ __('About Pressbooks', 'aldine') }}
@endslot
<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>
@slot('button_title')
{{ __('Learn More', 'aldine') }}
@endslot
@slot('button_url')
{{ network_home_url('/about/') }}
@endslot
{!! $block['content'] !!}
@endcomponent
@elseif($block_count < 4)
@for($i = 0; $i < $block_count; $i++)
<div class="block block-{{ $i + 1 }} flex flex-column items-center justify-center p-0 w-100">
<div class="inside tc">
@php(dynamic_sidebar($blocks[$i]))
</div>
</div>
@endfor
@foreach($blocks as $block)
@component('partials.front-page-block', [
'index' => $loop->iteration,
'title' => (isset($block['title'])) ? $block['title'] : false,
'button_title' => (isset($block['button_title'])) ? $block['button_title'] : false,
'button_url' => (isset($block['button_url'])) ? $block['button_url'] : false,
])
{!! $block['content'] !!}
@endcomponent
@endforeach
@elseif($block_count === 4)
<div class="one-two">
@for($i = 0; $i < 2; $i++)
<div class="block block-{{ $i + 1 }} flex flex-column items-center justify-center p-0 w-100">
<div class="inside tc">
@php(dynamic_sidebar($blocks[$i]))
</div>
</div>
@component('partials.front-page-block', [
'index' => $i + 1,
'title' => (isset($blocks[$i]['title'])) ? $blocks[$i]['title'] : false,
'button_title' => (isset($blocks[$i]['button_title'])) ? $blocks[$i]['button_title'] : false,
'button_url' => (isset($blocks[$i]['button_url'])) ? $blocks[$i]['button_url'] : false,
])
{!! $blocks[$i]['content'] !!}
@endcomponent
@endfor
</div>
@for($i = 2; $i < $block_count; $i++)
<div class="block block-{{ $i + 1 }} flex flex-column items-center justify-center p-0 w-100">
<div class="inside tc">
@php(dynamic_sidebar($blocks[$i]))
</div>
</div>
@component('partials.front-page-block', [
'index' => $i + 1,
'title' => (isset($blocks[$i]['title'])) ? $blocks[$i]['title'] : false,
'button_title' => (isset($blocks[$i]['button_title'])) ? $blocks[$i]['button_title'] : false,
'button_url' => (isset($blocks[$i]['button_url'])) ? $blocks[$i]['button_url'] : false,
])
{!! $blocks[$i]['content'] !!}
@endcomponent
@endfor
@endif
@if(get_theme_mod('pb_front_page_catalog'))
@if(is_active_sidebar('front-page-block'))
@component('partials.front-page-block', ['index' => 'custom', 'title' => false, 'button_title' => false, 'button_url' => false])
@php(dynamic_sidebar('front-page-block'))
@endcomponent
@endif
@if(get_option('pb_front_page_catalog'))
@include('partials.front-page-catalog')
@endif
@endsection

11
resources/views/partials/front-page-block.blade.php

@ -0,0 +1,11 @@
<div class="block block-{{ $index }} flex flex-column items-center justify-center p-0 w-100">
<div class="inside tc">
@if($title)
<h3 class="tc ttu">{{ $title }}</h3>
@endif
{{ $slot }}
@if($button_url && $button_title)
<a class="button" href="{{ $button_url }}">{{ $button_title }}</a>
@endif
</div>
</div>
Loading…
Cancel
Save