Skip to content

Commit

Permalink
SNOW-7: Various CSS tweaks and experimenting some sidebar changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkbulecount2 committed Jan 29, 2018
1 parent 23bc6ba commit cec99a3
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 120 deletions.
78 changes: 78 additions & 0 deletions category.php
@@ -0,0 +1,78 @@
<?php
/**
* For a category, display the category's landing page.
*
* To make a category landing page:
* 1. Make a post.
* 2. Give it a name you would recognize like "About Us Landing Page".
* This title is ignored and is useful only to identify it easily in the
* Wordpress admin.
* 3. Add the following into the post's Custom Fields:
* name: is_landing_page
* value: true
* 4. Assign the post to the category it's supposed to be a landing page for.
*
* @package a11y
*/
$category_name = '';
$category_landing_id = '';
$category_landing_content = '';
$category_current = get_the_category();

if ( ! empty( $category_current ) ) {
$category_name = $category_current[0]->name;
$args = array(
'post_type' => 'post',
'category_name' => $category_current[0]->slug,
'meta_query' => array (
array (
'key' => 'is_landing_page',
'value' => 'true',
'compare' => '=',
),
),
);
$the_query = new WP_Query($args);

while ( $the_query->have_posts() ) {
/* If there is a landing page for the category. */
$the_query->the_post();
$category_landing_content = get_the_content();
$category_landing_id = get_the_ID();
}
/* Restore original Post Data */
wp_reset_postdata();
}

get_header();
get_sidebar('post');
?>
<main id="content" class="a11y-site-main columns">
<h1><?php echo $category_name ?></h1>
<section>
<article>
<div class="a11y-entry-content">
<?php echo apply_filters('the_content', $category_landing_content); //do_shortcode ($category_landing_content); ?>
</div>
</article>
<?php if (empty ($category_landing_id)) {
/* No landing page to show, then list posts in the category. */
/* Start the Loop */
if (have_posts()) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;

the_posts_navigation();

/* Restore original Post Data */
wp_reset_postdata();
else :
echo wpautop ('No posts');
endif;
}
?>
</section>
</main>
<?php
get_footer();
124 changes: 84 additions & 40 deletions functions.php
Expand Up @@ -10,44 +10,6 @@ function snow_theme_enqueue_styles() {
}
add_action( 'wp_enqueue_scripts', 'snow_theme_enqueue_styles' );

/**
* a11y widgets for front page
*/

if (function_exists('register_sidebar')) {

register_sidebar(array(
'name' => 'Front Panel 1',
'id' => 'a11y-front-panel1',
'before_widget' => '<div id="%1$s" class="small-12 medium-4 columns a11y-front-panel">',
'after_widget' => '</div>',
'before_title' => '<h1 class="a11y-panel-header">',
'after_title' => '</h1>'
));
register_sidebar(array(
'name' => 'Front Panel 2',
'id' => 'a11y-front-panel2',
'before_widget' => '<div id="%1$s" class="small-12 medium-4 columns a11y-front-panel">',
'after_widget' => '</div>',
'before_title' => '<h1 class="a11y-panel-header">',
'after_title' => '</h1>'
));
register_sidebar(array(
'name' => 'Front Panel 3',
'id' => 'a11y-front-panel3',
'before_widget' => '<div id="%1$s" class="small-12 medium-4 columns a11y-front-panel">',
'after_widget' => '</div>',
'before_title' => '<h1 class="a11y-panel-header">',
'after_title' => '</h1>'
));
}

/* Add custom menu for sidebar */
function snow_sidebar_menu() {
register_nav_menu('snow_sidebar_menu',__( 'Sidebar Menu' ));
}
add_action( 'init', 'snow_sidebar_menu' );

/* Add SNOW introduction to front page */
register_sidebar( array(
'name' => __( 'Snow Home', 'snow' ),
Expand Down Expand Up @@ -169,13 +131,11 @@ function snow_upcoming_workshops() {
}
add_action('widgets_init', 'snow_upcoming_workshops');


function snow_feature_article() {
register_widget( new snow_panel_widget('snow_feature_article','Feature Article','22'));
}
add_action('widgets_init', 'snow_feature_article');


function snow_featured_content() {
register_widget( new snow_panel_widget('snow_featured_content','Featured Content','23'));
}
Expand All @@ -184,5 +144,89 @@ function snow_featured_content() {
/* Enable shortcodes */
add_filter('widget_text', 'do_shortcode');


if (function_exists('register_sidebar')) {
register_sidebar('post');
}

if (function_exists('register_sidebar')) {
register_sidebar('page');
}

function create_sidebar($post_type) {
$category_current = get_the_category();
$category_link = get_term_link ($category_current[0]->slug, "category");
$current_displayed_id = get_the_ID (); // the ID of the post currently displayed in the main content panel.

if ( ! empty( $category_current ) ) {
$args = array(
// get posts belonging to the current category.
'post_type' => $post_type,
'category_name' => $category_current[0]->slug,
);
$sidebar_query = new WP_Query($args);

if ($sidebar_query->have_posts()) :

/*
If there are more than 1 post in the current category,
then the first item should be a link to the category.
Otherwise if there's just 1 post, then it can be ignore as it
will be the landing page already being shown.
*/
if ($sidebar_query->found_posts > 1) :?>
<ul>
<li><a href="<?php echo $category_link; ?>" class="a11y-sidebar-category-link
<?php
if (! empty ($category_landing_id)) : ?>a11y-sidebar-current<?php endif;?>">
<?php
/*
if category_landing_id is not empty, then we are showing a
landing page. Therefore give it active styling.
*/
echo $category_current[0]->name; ?></a></li>

<li>
<ul>
<?php
while ( $sidebar_query->have_posts() ) : $sidebar_query->the_post();
/*
Display all pages in the category as a list of links.
But if one of the pages is the landing page, we skip it
since it's already the first item in the list.
*/

$is_landing_page = get_post_meta (get_the_ID(), 'is_landing_page', true);
if ( empty($is_landing_page) && (get_the_ID() != $category_landing_id)) :
// If the post isn't the landing page, show a link. Otherwise ignore it.
?>
<li>
<a href="<?php the_permalink() ?>"
<?php if ($current_displayed_id == get_the_ID() && empty ($category_landing_id)) :
/*
Check the category_landing_id if it is set, then we're displaying the
landing page. So don't show the active styling for this item.
*/
?>
class="a11y-sidebar-current"
aria-current="page"
<?php endif;?>>
<?php the_title(); ?>
</a>
</li>
<?php

endif;
endwhile;?>
</ul>
</li>
</ul>
<?php
endif;
endif;
}
}

?>

2 changes: 1 addition & 1 deletion page.php
Expand Up @@ -13,7 +13,7 @@
*/

get_header();
get_sidebar();
get_sidebar('page');
?>

<main id="content" class="a11y-site-main columns">
Expand Down
18 changes: 18 additions & 0 deletions sidebar-page.php
@@ -0,0 +1,18 @@
<?php
/**
* The sidebar containing the main widget area
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package a11y
*/

global $category_landing_id;
?>

<aside class="a11y-site-aside small-14 medium-4 columns" role="complementary">
<?php

create_sidebar('page');
?>
</aside>
18 changes: 18 additions & 0 deletions sidebar-post.php
@@ -0,0 +1,18 @@
<?php
/**
* The sidebar containing the main widget area
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package a11y
*/

global $category_landing_id;
?>

<aside class="a11y-site-aside small-14 medium-4 columns" role="complementary">
<?php
echo 'Hello';
create_sidebar('post');
?>
</aside>
77 changes: 0 additions & 77 deletions sidebar.php 100755 → 100644
Expand Up @@ -9,80 +9,3 @@

global $category_landing_id;
?>

<aside class="a11y-site-aside small-14 medium-4 columns" role="complementary">
<?php
$category_current = get_the_category();
$category_link = get_term_link ($category_current[0]->slug, "category");
$current_displayed_id = get_the_ID (); // the ID of the post currently displayed in the main content panel.

if ( ! empty( $category_current ) ) {
$args = array(
// get posts belonging to the current category.
'post_type' => 'post',
'category_name' => $category_current[0]->slug,
);
$sidebar_query = new WP_Query($args);

if ($sidebar_query->have_posts()) :

/*
If there are more than 1 post in the current category,
then the first item should be a link to the category.
Otherwise if there's just 1 post, then it can be ignore as it
will be the landing page already being shown.
*/
if ($sidebar_query->found_posts > 1) :?>
<ul>
<li><a href="<?php echo $category_link; ?>" class="a11y-sidebar-category-link
<?php
if (! empty ($category_landing_id)) : ?>a11y-sidebar-current<?php endif;?>">
<?php
/*
if category_landing_id is not empty, then we are showing a
landing page. Therefore give it active styling.
*/
echo $category_current[0]->name; ?></a></li>

<li>
<ul>
<?php
while ( $sidebar_query->have_posts() ) : $sidebar_query->the_post();
/*
Display all pages in the category as a list of links.
But if one of the pages is the landing page, we skip it
since it's already the first item in the list.
*/

$is_landing_page = get_post_meta (get_the_ID(), 'is_landing_page', true);
if ( empty($is_landing_page) && (get_the_ID() != $category_landing_id)) :
// If the post isn't the landing page, show a link. Otherwise ignore it.
?>
<li>
<a href="<?php the_permalink() ?>"
<?php if ($current_displayed_id == get_the_ID() && empty ($category_landing_id)) :
/*
Check the category_landing_id if it is set, then we're displaying the
landing page. So don't show the active styling for this item.
*/
?>
class="a11y-sidebar-current"
aria-current="page"
<?php endif;?>>
<?php the_title(); ?>
</a>
</li>
<?php

endif;
endwhile;?>
</ul>
</li>
</ul>
<?php
endif;
endif;
}
?>
</aside>
29 changes: 29 additions & 0 deletions single.php
@@ -0,0 +1,29 @@
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package a11y
*/

get_header();
get_sidebar('post');
?>
<main id="content" class="a11y-site-main columns">

<?php
while ( have_posts() ) : the_post();

get_template_part( 'template-parts/content', get_post_format() );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

endwhile; // End of the loop.
?>
</main>
<?php
get_footer();

0 comments on commit cec99a3

Please sign in to comment.