Browse Source

Fixes for #71 (#73)

* Redirect empty catalog to 404, hide empty landing page catalog, hide content editor for catalog page.

* PHPCS fix.

* Use ??.
pull/75/head
Ned Zimmerman 7 years ago committed by GitHub
parent
commit
1793386ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      404.php
  2. 1
      functions.php
  3. 18
      inc/actions/namespace.php
  4. 29
      page-catalog.php
  5. 2
      partials/content-front-page.php
  6. 20
      partials/content-page-catalog.php

24
404.php

@ -12,33 +12,13 @@ get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<section class="error-404 not-found">
<section class="error-404 not-found page-section">
<header class="page-header">
<h1 class="page-title"><?php esc_html_e( 'Oops! That page can&rsquo;t be found.', 'pressbooks-aldine' ); ?></h1>
</header><!-- .page-header -->
<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try a search?', 'pressbooks-aldine' ); ?></p>
<?php
get_search_form();
?>
<div class="widget widget_categories">
<h2 class="widget-title"><?php esc_html_e( 'Most Used Categories', 'pressbooks-aldine' ); ?></h2>
<ul>
<?php
wp_list_categories( [
'orderby' => 'count',
'order' => 'DESC',
'show_count' => 1,
'title_li' => '',
'number' => 10,
] );
?>
</ul>
</div><!-- .widget -->
<p><?php esc_html_e( 'It looks like nothing was found at this location.', 'pressbooks-aldine' ); ?></p>
</div><!-- .page-content -->
</section><!-- .error-404 -->

1
functions.php

@ -45,6 +45,7 @@ add_action( 'after_setup_theme', '\Aldine\Actions\setup' );
add_action( 'after_setup_theme', '\Aldine\Actions\content_width', 0 );
add_action( 'wp_head', '\Aldine\Actions\output_custom_colors' );
add_action( 'init', '\Aldine\Actions\add_editor_styles' );
add_action( 'admin_init', '\Aldine\Actions\hide_catalog_content_editor' );
add_filter( 'mce_buttons', '\Aldine\Filters\add_style_select' );
add_filter( 'tiny_mce_before_init', '\Aldine\Filters\add_blocks' );
add_filter( 'body_class', '\Aldine\Filters\body_classes' );

18
inc/actions/namespace.php

@ -202,3 +202,21 @@ function output_custom_colors() {
function remove_admin_bar_callback() {
remove_action( 'wp_head', '_admin_bar_bump_cb' );
}
/**
* Hide content editor for Catalog page.
*/
function hide_catalog_content_editor() {
$post_id = $_GET['post'] ?? null ;
if ( ! isset( $post_id ) ) {
return;
}
$pagename = get_the_title( $post_id );
if ( $pagename === 'Catalog' ) {
add_action( 'edit_form_after_title', function() {
printf( '<p>%s</p>', __( 'This page displays your network catalog, so there is no content to edit.', 'pressbooks-aldine' ) );
} );
remove_post_type_support( 'page', 'editor' );
remove_post_type_support( 'page', 'thumbnail' );
}
}

29
page-catalog.php

@ -9,12 +9,31 @@
* @package Aldine
*/
use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\get_catalog_licenses;
use function Aldine\Helpers\get_available_subjects;
use function Aldine\Helpers\get_available_licenses;
$current_page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$orderby = ( get_query_var( 'orderby' ) ) ? get_query_var( 'orderby' ) : 'title';
$subject = ( get_query_var( 'subject' ) ) ? get_query_var( 'subject' ) : '';
$license = ( get_query_var( 'license' ) ) ? get_query_var( 'license' ) : '';
$catalog_data = get_catalog_data( $current_page, 9, $orderby, $license, $subject );
$previous_page = ( $current_page > 1 ) ? $current_page - 1 : 0;
$next_page = $current_page + 1;
$licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data );
$subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data );
if ( ! empty( $catalog_data['books'] ) ) : ?>
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php get_template_part( 'partials/content', 'page-catalog' ); ?>
<?php include( locate_template( 'partials/content-page-catalog.php' ) ); ?>
</main><!-- #main -->
</div><!-- #primary -->
@ -22,3 +41,11 @@ get_header(); ?>
<?php
get_sidebar();
get_footer();
else :
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
endif;

2
partials/content-front-page.php

@ -37,7 +37,7 @@ if ( get_option( 'pb_front_page_catalog' ) ) {
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php if ( get_option( 'pb_front_page_catalog' ) ) : ?>
<?php if ( get_option( 'pb_front_page_catalog' ) && ! empty( $catalog_data['books'] ) ) : ?>
<div id="latest-books" class="latest-books">
<h2 id="latest-books-title"><?php echo $latest_books_title; ?></h2>
<div class="slider" role="region" aria-labelledby="latest-books-title" data-total-pages="<?php echo $catalog_data['pages']; ?>" <?php if ( $next_page <= $catalog_data['pages'] ) : ?>data-next-page="<?php echo $next_page; ?>"<?php endif; ?>>

20
partials/content-page-catalog.php

@ -9,26 +9,6 @@
?>
<?php
use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\get_catalog_licenses;
use function Aldine\Helpers\get_available_subjects;
use function Aldine\Helpers\get_available_licenses;
$current_page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$orderby = ( get_query_var( 'orderby' ) ) ? get_query_var( 'orderby' ) : 'title';
$subject = ( get_query_var( 'subject' ) ) ? get_query_var( 'subject' ) : '';
$license = ( get_query_var( 'license' ) ) ? get_query_var( 'license' ) : '';
$catalog_data = get_catalog_data( $current_page, 9, $orderby, $license, $subject );
$previous_page = ( $current_page > 1 ) ? $current_page - 1 : 0;
$next_page = $current_page + 1;
$licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data );
$subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data );
?>
<?php get_template_part( 'partials/page', 'header' ); ?>
<section class="network-catalog">
<form role="form" class="filter-sort" method="get">

Loading…
Cancel
Save