Browse Source

Optimize catalog further.

pull/21/head
Ned Zimmerman 7 years ago
parent
commit
cedbe86f8c
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 32
      app/controllers/App.php
  2. 7
      app/controllers/FrontPage.php
  3. 5
      app/controllers/PageCatalog.php
  4. 16
      resources/views/page-catalog.blade.php
  5. 8
      resources/views/partials/front-page-catalog.blade.php

32
app/controllers/App.php

@ -100,24 +100,26 @@ class App extends Controller
return (get_query_var('orderby')) ? get_query_var('orderby') : 'title';
}
public static function previousPage($page)
public function previousPage()
{
if (is_front_page()) {
$page = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
}
return ($page > 1) ? $page - 1 : 0;
}
public static function nextPage($page, $per_page = 10)
public function nextPage()
{
return ($page < App::totalPages($per_page)) ? $page + 1 : 0;
}
if (is_front_page()) {
$page = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
}
public static function totalPages($per_page = 10)
{
$request = new \WP_REST_Request('GET', '/pressbooks/v2/books');
$request->set_query_params([
'per_page' => $per_page,
]);
$response = rest_do_request($request);
return $response->headers['X-WP-TotalPages'];
return $page + 1;
}
public static function books($page = 1, $per_page = 10, $orderby = 'title', $license = '', $subject = '')
@ -128,6 +130,7 @@ class App extends Controller
'per_page' => $per_page,
]);
$response = rest_do_request($request);
$pages = $response->headers['X-WP-TotalPages'];
$data = rest_get_server()->response_to_data($response, true);
$books = [];
foreach ($data as $key => $book) {
@ -139,9 +142,10 @@ class App extends Controller
$books[] = $book;
}
if ($orderby === 'latest') {
return wp_list_sort($books, $orderby, 'desc');
$books = wp_list_sort($books, $orderby, 'desc');
} else {
return wp_list_sort($books, $orderby);
$books = wp_list_sort($books, $orderby);
}
return ['pages' => $pages, 'books' => $books];
}
}

7
app/controllers/FrontPage.php

@ -29,14 +29,9 @@ class FrontPage extends Controller
return __('Our Latest Titles', 'aldine');
}
public function totalPages()
{
return App::totalPages(3);
}
public function books()
{
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$page = (get_query_var('page')) ? get_query_var('page') : 1;
return App::books($page, 3);
}
}

5
app/controllers/PageCatalog.php

@ -100,11 +100,6 @@ class PageCatalog extends Controller
];
}
public function totalPages()
{
return App::totalPages(9);
}
public function books()
{
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;

16
resources/views/page-catalog.blade.php

@ -33,22 +33,22 @@
<div class="sort">
<a href="#sort">{{ __('Sort by', 'aldine') }} <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul id="sort" class="sorts">
<li><a data-sort="title" href="{{ network_home_url("/catalog/page/$current_page/?orderby=title") }}">{{ __('Title', 'aldine') }}</a></li>
<li><a data-sort="subject" href="{{ network_home_url("/catalog/page/$current_page/?orderby=subject") }}">{{ __('Subject', 'aldine') }}</a></li>
<li><a data-sort="latest" href="{{ network_home_url("/catalog/page/$current_page/?orderby=latest") }}">{{ __('Latest', 'aldine') }}</a></li>
<li><a data-sort="title" href="{{ "/catalog/page/$current_page/?orderby=title" }}">{{ __('Title', 'aldine') }}</a></li>
<li><a data-sort="subject" href="{{ "/catalog/page/$current_page/?orderby=subject" }}">{{ __('Subject', 'aldine') }}</a></li>
<li><a data-sort="latest" href="{{ "/catalog/page/$current_page/?orderby=latest" }}">{{ __('Latest', 'aldine') }}</a></li>
</ul>
</div>
</div>
<div class="books">
@foreach($books as $book)
@foreach($books['books'] as $book)
@include('partials.book', ['book' => $book])
@endforeach
</div>
@if($total_pages > 1)
@if($books['pages'] > 1)
<nav class="catalog-navigation">
@if(App::previousPage($current_page))<a class="previous" data-page="{{ App::previousPage($current_page) }}" href="{{ network_home_url('/catalog/page/' . App::previousPage($current_page) . '/') }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/left-arrow.svg')) {{ __('Previous', 'aldine') }}</a>@endif
@if($previous_page)<a class="previous" data-page="{{ $previous_page }}" href="{{ network_home_url("/catalog/page/$previous_page/") }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/left-arrow.svg')) {{ __('Previous', 'aldine') }}</a>@endif
<div class="pages">
@for($i = 1; $i <= $total_pages; $i++)
@for($i = 1; $i <= $books['pages']; $i++)
@if($i === $current_page)
<span class="current">{{ $i }}</span>
@else
@ -56,7 +56,7 @@
@endif
@endfor
</div>
@if(App::nextPage($current_page, 9))<a class="next" data-page="{{ App::nextPage($current_page, 9) }}" href="{{ network_home_url('/catalog/page/' . App::nextPage($current_page, 9) . '/') }}">{{ __('Next', 'aldine') }} @php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/right-arrow.svg'))</a>@endif
@if($next_page <= $books['pages'])<a class="next" data-page="{{ $next_page }}" href="{{ network_home_url("/catalog/page/$next_page/") }}">{{ __('Next', 'aldine') }} @php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/right-arrow.svg'))</a>@endif
</nav>
@endif
</section>

8
resources/views/partials/front-page-catalog.blade.php

@ -1,8 +1,8 @@
<div id="latest-titles" class="latest-books w-100">
<h3 class="tc ttu">{{ $latest_books_title }}</h3>
<div class="track flex flex-row flex-wrap justify-center items-center">
<div class="books flex flex-column justify-center items-center order-0 order-1-l flex-row-l justify-between-l" data-total-pages="{{ $total_pages }}" data-next-page="2">
@foreach($books as $book)
<div class="books flex flex-column justify-center items-center order-0 order-1-l flex-row-l justify-between-l" data-total-pages="{{ $books['pages'] }}" data-next-page="2">
@foreach($books['books'] as $book)
<div class="book flex flex-column justify-end w-100">
@if(isset($book['metadata']['keywords']))
<p class="subject tc ma0">
@ -18,8 +18,8 @@
</div>
@endforeach
</div>
@if(App::previousPage($current_page))<a class="previous db mr-auto f1 order-1 order-0-l" data-page="{{ App::previousPage($current_page) }}" href="{{ network_home_url('/page/' . App::previousPage($current_page) . '/#latest-titles') }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/left-arrow.svg'))</a>@endif
@if(App::nextPage($current_page, 3))<a class="next ml-auto order-2 db f1" data-page="{{ App::nextPage($current_page, 3) }}" href="{{ network_home_url('/page/' . App::nextPage($current_page, 3) . '/#latest-titles') }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/right-arrow.svg'))</a>@endif
@if($previous_page)<a class="previous db mr-auto f1 order-1 order-0-l" data-page="{{ $previous_page }}" href="{{ network_home_url("/page/$previous_page/#latest-titles") }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/left-arrow.svg'))</a>@endif
@if($next_page <= $books['pages'])<a class="next ml-auto order-2 db f1" data-page="{{ $next_page }}" href="{{ network_home_url("/page/$next_page/#latest-titles") }}">@php(include get_theme_file_path() . '/dist/' . Aldine\svg_path('images/right-arrow.svg'))</a>@endif
</div>
<div class="catalog-link tc">
<a class="button button-inverse button-wide" href="{{ network_home_url('/catalog/') }}">{{ __('View Complete Catalog', 'aldine') }}</a>

Loading…
Cancel
Save