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', 'section' => 'pb_network_social',
'settings' => 'pb_network_twitter', 'settings' => 'pb_network_twitter',
]); ]);
$wp_customize->add_section('pb_network_catalog', [ $wp_customize->add_section('pb_front_page_content', [
'title' => __('Catalog', 'aldine'), 'title' => __('Front Page Content', 'aldine'),
'priority' => 20, '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', [ $wp_customize->add_control('pb_front_page_catalog', [
'label' => __('Show Front Page Catalog', 'aldine'), 'label' => __('Show Front Page Catalog', 'aldine'),
'section' => 'pb_network_catalog', 'section' => 'pb_front_page_catalog',
'settings' => 'pb_front_page_catalog', 'settings' => 'pb_front_page_catalog',
'type' => 'checkbox' 'type' => 'checkbox'
]); ]);
$wp_customize->add_setting('pb_front_page_catalog_title', [ $wp_customize->add_setting('pb_front_page_catalog_title', [
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field' 'sanitize_callback' => 'sanitize_text_field'
]); ]);
$wp_customize->add_control('pb_front_page_catalog_title', [ $wp_customize->add_control('pb_front_page_catalog_title', [
'label' => __('Front Page Catalog Title', 'aldine'), 'label' => __('Front Page Catalog Title', 'aldine'),
'section' => 'pb_network_catalog', 'section' => 'pb_front_page_catalog',
'settings' => 'pb_front_page_catalog_title', 'settings' => 'pb_front_page_catalog_title',
]); ]);
}); });

37
app/controllers/FrontPage.php

@ -9,13 +9,8 @@ class FrontPage extends Controller
public function blockCount() public function blockCount()
{ {
$c = 0; $c = 0;
foreach ([ for ($i = 1; $i < 5; $i++) {
'home-block-1', if (get_option("pb_front_page_block_${i}_content")) {
'home-block-2',
'home-block-3',
'home-block-4'
] as $block) {
if (is_active_sidebar($block)) {
$c++; $c++;
} }
} }
@ -25,10 +20,23 @@ class FrontPage extends Controller
public function blocks() public function blocks()
{ {
$blocks = []; $blocks = [];
for ($i = 0; $i < 4; $i++) { for ($i = 1; $i < 5; $i++) {
if (is_active_sidebar("home-block-$i")) { $block = [];
$blocks[] = "home-block-$i"; $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; return $blocks;
@ -57,9 +65,12 @@ class FrontPage extends Controller
public function latestBooksTitle() public function latestBooksTitle()
{ {
return (empty(get_theme_mod('pb_front_page_catalog_title'))) ? $title = get_option('pb_front_page_catalog_title');
__('Our Latest Titles', 'aldine') : if ($title) {
get_theme_mod('pb_front_page_catalog_title'); return $title;
}
return __('Our Latest Titles', 'aldine');
} }
public static function latestBooks($page = 1, $per_page = 3) 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>' 'after_title' => '</h3>'
]; ];
register_sidebar([ register_sidebar([
'name' => __('Home Block 1', 'aldine'), 'name' => __('Front Page Content', 'aldine'),
'id' => 'home-block-1' 'id' => 'front-page-block'
] + $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'
] + $config); ] + $config);
register_sidebar([ register_sidebar([
'name' => __('Network Footer Block 1', 'aldine'), 'name' => __('Network Footer Block 1', 'aldine'),

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

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