Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Add example theme / simple theme / adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WP committed Nov 13, 2022
1 parent 0c5f287 commit a54994c
Show file tree
Hide file tree
Showing 40 changed files with 696 additions and 34 deletions.
13 changes: 13 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
get_header();
?>

<section>
<header>
<h1>404</h1>
</header>
<p>Page not found.</p>
</section>

<?php
get_footer();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/assets/js/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const navigation = document.getElementById('navigation');
const editor = document.getElementById('editor');
const mainContent = document.getElementById('main-content');
const handle = document.getElementById('handle');
const lineNumbers = document.getElementById('line-numbers');

document.addEventListener("DOMContentLoaded", function () {
handle.addEventListener('mousedown', setupEditorResizer, false);
window.addEventListener('resize', updateLineNumbers);
updateLineNumbers();
});

let StartX, contentStartWidth;

function setupEditorResizer(event) {
StartX = event.clientX;
contentStartWidth = parseInt(window.getComputedStyle(navigation).width, 10);
document.documentElement.addEventListener('mousemove', dragEditorResizerCallback, false);
document.documentElement.addEventListener('mouseup', destroyEditorResizerCallback, false);
}

function dragEditorResizerCallback(event) {
// Don't allow going under 280px or over 45% viewport width
if (event.clientX > 280 && event.clientX < window.innerWidth * 0.45) {
navigation.style.flexBasis = event.clientX + 'px';
updateLineNumbers();
}
}

function destroyEditorResizerCallback() {
document.documentElement.removeEventListener('mousemove', dragEditorResizerCallback, false);
document.documentElement.removeEventListener('mouseup', destroyEditorResizerCallback, false);
}

function updateLineNumbers() {
// Remove all line numbers
lineNumbers.querySelectorAll('i').forEach(n => n.remove());

// Set up the line numbers container height
lineNumbers.style.height = mainContent.scrollHeight + 'px';

// Calculate how many line numbers we want and append them to the DOM
const totalNumbers = (mainContent.scrollHeight) / 35;
Array.from({length: totalNumbers}, () => {
lineNumbers.appendChild(document.createElement("i"));
});
}
12 changes: 12 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
</main><!-- /#main-content -->
</div><!-- /#editor -->
</div><!-- /#resizable-area -->

<footer id="site-footer">
<span>wpcms.dev</span>
</footer>

<?php wp_footer(); ?>

</body>
</html>
24 changes: 24 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace wpcms\example_theme;

// Let WP CMS manage the document title
add_theme_support( 'title-tag' );

// Enable support for Post Thumbnails on posts and pages
add_theme_support( 'post-thumbnails' );

// Include primary navigation menu
function setup_navigation() {
register_nav_menus( array(
'primary-menu' => 'Primary Menu',
) );
}
add_action( 'init', 'wpcms\example_theme\setup_navigation' );

// Enqueue scripts and styles
function enqueue_stuff() {
wp_enqueue_style( 'general-style', get_stylesheet_uri() );
wp_enqueue_script( 'global-js', get_template_directory_uri() . '/assets/js/global.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpcms\example_theme\enqueue_stuff' );
39 changes: 39 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>

<a class="screen-reader-text" href="#main-content">Skip to content</a>

<?php
if ( ! is_admin_bar_showing() ) {
?>
<aside id="top-bar">
<span class="version">WP CMS v<?php bloginfo( 'version' ); ?></span>
</aside>
<?php
}
?>

<div id="resizable-area">
<header id="navigation">
<h1 class="site-title"><a href="<?php echo esc_url( home_url() ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
<hr>
<nav id="main-menu">
<?php
wp_nav_menu( array(
'theme_location' => 'primary-menu',
'menu_id' => 'primary-menu',
) );
?>
</nav>
<div id="handle"></div>
</header>
<div id="editor">
<aside id="line-numbers"></aside>
<main id="main-content">
16 changes: 16 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
get_header();

if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/listed-post', get_post_type() );
}
the_posts_pagination( array(
'prev_text' => __( 'Previous page' ),
'next_text' => __( 'Next page' ),
) );
}

get_sidebar();
get_footer();
10 changes: 10 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
get_header();

while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/post-content' );
}

get_sidebar();
get_footer();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* The template for displaying search results
*/

get_header();

if ( have_posts() ) { ?>
<h1>Results for: <?php echo get_search_query(); ?></h1>
<?php
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/listed-post', 'search' );
}
} else {
?>
<p>Sorry, but nothing matched your search query.</p>
<?php
}

get_sidebar();
get_footer();
1 change: 1 addition & 0 deletions src/wp-content/themes/wp-cms-example-theme/sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
10 changes: 10 additions & 0 deletions src/wp-content/themes/wp-cms-example-theme/single.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
get_header();

while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/post-content', get_post_type() );
}

get_sidebar();
get_footer();
Loading

0 comments on commit a54994c

Please sign in to comment.