...
 
Commits (11)
<?php
global $post;
ob_start();
// 404 template content
?>
<h1>404 - Page not found</h1>
<p>The requested page could not be found.</p>
<?php
// create dummy post from content and add to query
$post = new WP_Post( (object)[ 'post_content' => ob_get_clean(), 'filter' => 'raw' ] );
$wp_query->posts[] = $post;
$wp_query->post_count = 1;
$grund->the_layout();
<?php
$grund_theme->the_layout();
$grund->the_layout();
......@@ -2,23 +2,11 @@
class grund_theme
{
var $default_query_vars = [
'layout' => null,
'view' => null,
'listing' => null,
'listed' => null,
'detail' => null,
'sidebar' => null,
'listing_class' => null,
'listed_class' => null,
];
function __construct()
{
global $wp_query;
global $grund, $wp_query;
$this->query_stack = [];
$this->the_query = $wp_query;
$grund->the_query = $wp_query;
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
add_action( 'init', [ $this, 'init' ] );
......@@ -47,142 +35,6 @@ class grund_theme
wp_enqueue_style( 'grund-styles', get_stylesheet_uri() );
}
function push_query( $new_query )
{
global $wp_query;
$this->query_stack[] = $this->the_query;
$this->the_query = $wp_query = $new_query;
}
function pop_query()
{
global $wp_query;
$this->the_query = $wp_query = array_pop( $this->query_stack );
$this->the_query->reset_postdata();
return $this->the_query;
}
function the_layout( $layout = null )
{
if ( ! $layout )
$layout = $this->the_query->get( 'layout' );
else
$this->the_query->set( 'layout', $layout );
get_template_part( 'layout/layout', $layout );
}
function the_view( $view = null )
{
if ( ! $view )
$view = $this->the_query->get( 'view' );
if ( $view == 'listing' || $this->the_query->is_archive() || $this->the_query->is_home() )
{
$this->the_query->set( 'view', 'listing' );
$this->listing();
}
else
{
$this->the_query->set( 'view', 'detail' );
$this->detail();
}
}
function listing( $listing = null )
{
if ( ! $listing )
$listing = $this->the_query->get( 'listing' );
else
$this->the_query->set( 'listing', $listing );
get_template_part( 'listing/listing', $listing );
}
function listing_class( $extra = [] )
{
$classes = [ 'listing' ];
if ( $query_classes = $this->the_query->get( 'listing_class' ) )
$classes[] = $query_classes;
if ( $listing = $this->the_query->get( 'listing' ) )
$classes[] = 'listing-' . $listing;
return $this->maybe_attr( 'class', join( ' ', array_merge( $classes, $extra ) ) );
}
function listed( $listed = null )
{
global $post;
if ( ! $listed )
$listed = $this->the_query->get( 'listed', $post->post_type );
else
$this->the_query->set( 'listed', $listed );
get_template_part( 'listed/listed', $listed );
}
function listed_class( $extra = [] )
{
global $post;
$classes = [ 'listed' ];
if ( $query_classes = $this->the_query->get( 'listed_class' ) )
$classes[] = $query_classes;
if ( $listed = $this->the_query->get( 'listed' ) )
$classes[] = 'listed-' . $listed;
return $this->maybe_attr( 'class',
join( ' ',
get_post_class(
array_merge( $classes, $extra )
, $post->ID )
)
);
}
function detail( $detail = null )
{
global $post;
if ( ! $detail )
$detail = $this->the_query->get( 'detail', $post->post_type );
else
$this->the_query->set( 'detail', $detail );
if ( $this->the_query->have_posts() )
{
$this->the_query->the_post();
get_template_part( 'detail/detail', $detail );
}
}
function detail_class( $extra = [] )
{
global $post;
$classes = [ 'detail' ];
if ( $detail = $this->the_query->get( 'detail' ) )
$classes[] = 'detail-' . $detail;
return $this->maybe_attr( 'class',
join( ' ',
get_post_class(
array_merge( $classes, $extra )
, $post->ID )
)
);
}
function get_the_page_title()
{
global $s;
......@@ -198,19 +50,6 @@ class grund_theme
else
return wp_title( '', false );
}
/*
Return an html attribute if the value is set, otherwise return nothing.
*/
function maybe_attr( $attr, $val, $space = true )
{
if ( $val )
{
return ( $space ? ' ' : '' ) . $attr . '="' . $val . '"';
}
return '';
}
}
$grund_theme = new grund_theme();
<?php
global $grund_theme;
global $grund;
?>
<article <?=$grund_theme->detail_class()?>>
<article <?=$grund->detail_class()?>>
<header>
<h1><?php the_title() ?></h1>
</header>
......
<?php
# Classes
require "class/theme.php";
# Custom Post Types
// require "post-type/TYPENAME.php";
# Shortcodes
require "shortcode/listing.php";
// require "shortcode/SHORTCODE.php";
......@@ -11,6 +11,9 @@ if ( $logo )
<!DOCTYPE html>
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?=( ( $title = $grund_theme->get_the_page_title() ) ? $title . ' - ' : '' )?><?php bloginfo( 'name' )?></title>
<?php wp_head() ?>
</head>
......
<?php
$grund_theme->the_layout( 'sidebar' );
$grund->the_layout( 'sidebar' );
<?php
$grund_theme->the_layout();
$grund->the_layout();
......@@ -2,5 +2,4 @@
/**
* Template Name: Sidebar
*/
global $grund_theme;
$grund_theme->the_layout( 'sidebar' );
$grund->the_layout( 'sidebar' );
<?php
global $grund_theme;
global $grund, $grund_theme;
// Get which sidebar to show
$sidebar = $grund_theme->the_query->get( 'sidebar', 'sidebar' );
$sidebar = $grund->the_query->get( 'sidebar', 'sidebar' );
// Ensure it has widgets
if ( is_active_sidebar( $sidebar ) )
......@@ -15,7 +15,7 @@ if ( is_active_sidebar( $sidebar ) )
}
?>
<div>
<?php $grund_theme->the_view(); ?>
<?php $grund->the_view(); ?>
</div>
<div>
<?php get_sidebar( $sidebar ) ?>
......@@ -26,6 +26,6 @@ if ( is_active_sidebar( $sidebar ) )
else
{
// Fallback to sidebar-less layout
$grund_theme->the_query->set( 'layout', null );
$grund_theme->the_layout();
$grund->the_query->set( 'layout', null );
$grund->the_layout();
}
<?php
global $grund_theme;
global $grund, $grund_theme;
get_header();
......@@ -8,5 +8,5 @@ if ( is_archive() || is_home() )
?><h1><?=$grund_theme->get_the_page_title()?></h1><?php
}
$grund_theme->the_view();
$grund->the_view();
get_footer();
\ No newline at end of file
<?php
global $grund_theme;
global $grund;
?>
<article <?=$grund_theme->listed_class()?>>
<article <?=$grund->listed_class()?>>
<header>
<h2><a href="<?=get_the_permalink()?>"><?php the_title() ?></a></h2>
</header>
......
<?php
global $wp_query, $grund_theme;
global $wp_query, $grund;
?>
<div<?=$grund_theme->listing_class()?>>
<div<?=$grund->listing_class()?>>
<?php
while ( $wp_query->have_posts() )
{
$wp_query->the_post();
$grund_theme->listed();
}
$grund->listing_loop();
?>
</div>
\ No newline at end of file
<?php
add_shortcode( 'listing', function ( $atts, $content ) {
global $grund_theme, $wp_query;
// grund default query vars + wp default query vars + shortcode defaults + given shortcode atts
$atts = shortcode_atts( wp_parse_args( [
'post_type' => 'post',
'posts_per_page' => -1,
], WP_Query::fill_query_vars( $grund_theme->default_query_vars ) ), $atts, 'listing' );
$grund_theme->push_query( new WP_Query( $atts ) );
ob_start();
$grund_theme->listing();
$grund_theme->pop_query();
return ob_get_clean();
} );
<?php
global $grund_theme;
$sidebar = $grund_theme->the_query->get( 'sidebar', 'sidebar' );
global $grund;
$sidebar = $grund->the_query->get( 'sidebar', 'sidebar' );
?>
<div id="sidebar-$sidebar" class="sidebar">
<?php dynamic_sidebar( $sidebar ); ?>
......
/*!
Theme Name: Grund
Theme Name: grund theme
Author: Martin Hultén-Ashauer
Author URI: http://nimdraug.com
Version: 0.1-dev
......