Commit c8f4d529 authored by Michael Iseard's avatar Michael Iseard
Browse files

Update FAQ and page templates

parent 9dd1b6b2
......@@ -37,12 +37,48 @@ class App extends Controller
switch($size) {
case 'small':
return asset_path('images/logo-light.svg');
break;
case 'full':
return asset_path('images/logo-light-full.svg');
break;
case 'white':
return asset_path('images/logo-white.svg');
}
return false;
}
public function site_news()
{
if (is_front_page() || carbon_get_theme_option('site_news_all_pages')) {
if (carbon_get_theme_option('show_site_news')) {
return carbon_get_theme_option('site_news');
}
}
return false;
}
/**
* @return array
*/
public function cta()
{
$cta['label'] = carbon_get_theme_option('cta_label');
$cta['link'] = carbon_get_theme_option('cta_link');
return $cta;
}
/**
* Primary Nav Menu arguments
* @return array
*/
public function primarymenu()
{
$args = array(
'theme_location' => 'primary_navigation',
'menu_class' => 'navbar-nav',
'walker' => new \App\wp_bootstrap4_navwalker(),
);
return $args;
}
}
......@@ -24,38 +24,42 @@ class FrontPage extends Controller
function __construct()
{
$intro_image_id = carbon_get_theme_option('intro_image');
if($intro_image_id) {
if ($intro_image_id) {
$this->intro_image_id = $intro_image_id;
$this->intro_image = get_post($this->intro_image_id);
}
$this->intro_content = carbon_get_theme_option('intro_text');
}
public function intro_image($size='full') {
public function intro_image($size = 'full')
{
$intro_image_id = $this->intro_image_id;
if($intro_image_id) {
if ($intro_image_id) {
return wp_get_attachment_image_url($intro_image_id, $size);
}
return false;
}
public function intro_image_caption() {
public function intro_image_caption()
{
$intro_image = $this->intro_image;
if($intro_image) {
if ($intro_image) {
return $intro_image->post_excerpt;
}
return false;
}
public function intro_image_description() {
public function intro_image_description()
{
$intro_image = $this->intro_image;
if($intro_image) {
if ($intro_image) {
return $intro_image->post_content;
}
return false;
}
public function intro_content() {
public function intro_content()
{
$content = $this->intro_content;
return filter_handlebar($content);
......
......@@ -8,8 +8,20 @@ use WP_Query;
class TemplateFaq extends Controller
{
public function current_category() {
return get_query_var( 'category' );
/**
* TemplateFaq constructor.
*/
public function __construct()
{
set_query_var('template_name', 'faq');
}
/**
* @return mixed
*/
public function current_category()
{
return get_query_var('category');
}
/**
......@@ -17,9 +29,10 @@ class TemplateFaq extends Controller
* @param null $keyword
* @return WP_Query
*/
public function questions($category=null, $keyword=null) {
public function questions($category = null, $keyword = null)
{
if(!$category) {
if (!$category) {
$category=$this->current_category();
}
......@@ -32,22 +45,23 @@ class TemplateFaq extends Controller
'orderby' => 'menu_order',
];
if($category) {
if ($category) {
$args['category_name'] = $category;
}
if($keyword) {
if ($keyword) {
$args['s'] = $keyword;
}
// The Query
return new WP_Query( $args );
return new WP_Query($args);
}
/**
* @return array
*/
public function categories() {
public function categories()
{
$args = [
'type' => 'faq',
......@@ -62,11 +76,9 @@ class TemplateFaq extends Controller
array_unshift($categories, (object) [
'slug' => null,
'name' => __('All', 'kudos-website')
]
);
]);
return $categories;
}
}
......@@ -91,20 +91,32 @@ add_filter('comments_template', function ($comments_template) {
}, 100);
// Custom SMTP settings
add_action( 'phpmailer_init', function( $phpmailer ) {
$useSMTP = carbon_get_theme_option('we_use_smtp');
if ($useSMTP) {
$phpmailer->isSMTP();
$phpmailer->Host = carbon_get_theme_option('we_smtp_host');
$phpmailer->SMTPAutoTLS = true;
$phpmailer->SMTPAuth = true;
$phpmailer->Port = carbon_get_theme_option('we_smtp_port');
$phpmailer->Username = carbon_get_theme_option('we_smtp_user');
$phpmailer->Password = carbon_get_theme_option('we_smtp_password');
// Additional settings
$phpmailer->SMTPSecure = carbon_get_theme_option('we_security_protocol');
$phpmailer->From = carbon_get_theme_option('we_from_email');
$phpmailer->FromName = carbon_get_theme_option('we_from_name');
}
});
\ No newline at end of file
add_action('phpmailer_init', function ($phpmailer) {
$useSMTP = carbon_get_theme_option('we_use_smtp');
if ($useSMTP) {
$phpmailer->isSMTP();
$phpmailer->Host = carbon_get_theme_option('we_smtp_host');
$phpmailer->SMTPAutoTLS = true;
$phpmailer->SMTPAuth = true;
$phpmailer->Port = carbon_get_theme_option('we_smtp_port');
$phpmailer->Username = carbon_get_theme_option('we_smtp_user');
$phpmailer->Password = carbon_get_theme_option('we_smtp_password');
// Additional settings
$phpmailer->SMTPSecure = carbon_get_theme_option('we_security_protocol');
$phpmailer->From = carbon_get_theme_option('we_from_email');
$phpmailer->FromName = carbon_get_theme_option('we_from_name');
}
});
/**
* Register custom query vars
*
* @param array $vars The array of available query variables
*
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars
*/
add_filter('query_vars', function ($vars) {
$vars[] = 'category';
return $vars;
});
......@@ -13,8 +13,8 @@ use Roots\Sage\Template\BladeProvider;
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery', 'wp-api'], null, true);
wp_localize_script('sage/main.js', 'kudos-website', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
wp_localize_script('sage/main.js', 'kudos_website', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce'),
'site_url' => get_site_url(),
'page_name' => get_query_var('pagename'),
......@@ -159,14 +159,15 @@ add_action('after_setup_theme', function () {
*/
// Hooking up our function to theme setup
add_action( 'init', function() {
add_action('init', function () {
register_post_type( 'reviews',
register_post_type(
'reviews',
// CPT Options
[
'labels' => [
'name' => __( 'Reviews', 'kudos-website' ),
'singular_name' => __( 'Review', 'kudos-website' ),
'name' => __('Reviews', 'kudos-website'),
'singular_name' => __('Review', 'kudos-website'),
'add_new' => __('New Review', 'kudos-website'),
'add_new_item' => __('Add Review', 'kudos-website')
],
......@@ -183,14 +184,15 @@ add_action( 'init', function() {
*/
// Hooking up our function to theme setup
add_action( 'init', function() {
add_action('init', function () {
register_post_type( 'faq',
register_post_type(
'faq',
// CPT Options
[
'labels' => [
'name' => __( 'FAQ', 'kudos-website' ),
'singular_name' => __( 'Question', 'kudos-website' ),
'name' => __('FAQ', 'kudos-website'),
'singular_name' => __('Question', 'kudos-website'),
'add_new' => __('New Question', 'kudos-website'),
'add_new_item' => __('Add Question', 'kudos-website')
],
......@@ -212,17 +214,13 @@ add_action( 'init', function() {
* @source https://wordpress.stackexchange.com/questions/257899/add-rewrite-rule-not-working-for-page-var
*/
add_action( 'init', function () {
add_rewrite_tag(
'%category%',
'([^/]+)'
);
add_action('init', function () {
add_rewrite_rule(
'^help/([^/]+)/?',
'index.php?pagename=help&category=$matches[1]',
'^faq/([^/]+)/?',
'index.php?pagename=faq&category=$matches[1]',
'top'
);
} );
});
add_action('admin_init', function () {
// Redirect any user trying to access comments page
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ad3823aaee695a41fc93645e79477545",
"content-hash": "411e688478efc1c6337d594ae34f9195",
"packages": [
{
"name": "brain/hierarchy",
......@@ -818,6 +818,49 @@
],
"time": "2020-04-07T20:44:10+00:00"
},
{
"name": "mwdelaney/sage-bootstrap4-navwalker",
"version": "1.6",
"source": {
"type": "git",
"url": "https://github.com/MWDelaney/sage-bootstrap4-navwalker.git",
"reference": "0751a0303d66b9b421ba8901c1c6391a51158242"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MWDelaney/sage-bootstrap4-navwalker/zipball/0751a0303d66b9b421ba8901c1c6391a51158242",
"reference": "0751a0303d66b9b421ba8901c1c6391a51158242",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"autoload": {
"files": [
"bootstrap4-navwalker.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael W. Delaney",
"email": "michael@michaeldelaney.me"
}
],
"description": "Bootstrap 4 Navbar component navwalker for Sage 9 based themes",
"homepage": "https://github.com/MWDelaney/sage-bootstrap4-navwalker",
"keywords": [
"bootstrap 4",
"navbar",
"navwalker",
"wordpress"
],
"time": "2020-09-03T19:39:06+00:00"
},
{
"name": "nesbot/carbon",
"version": "1.25.3",
......
// import external dependencies
import 'jquery';
import { library, dom } from '@fortawesome/fontawesome-svg-core';
import { faFemale, faMale, faStar, faTimes } from '@fortawesome/free-solid-svg-icons';
library.add(faFemale, faMale, faStar, faTimes);
import { faFemale, faMale, faStar, faTimes, faBars } from '@fortawesome/free-solid-svg-icons';
library.add(faFemale, faMale, faStar, faTimes, faBars);
dom.watch();
// Import everything from autoload
......
export default {
init() {
init() {
const $hamburgerToggle = $('.hamburger');
// JavaScript to be fired on all pages
$hamburgerToggle.click(function() {
$(this).toggleClass('is-active');
});
$('body').click(function (e) {
let target = $(e.target);
if(!target.is($('[class*="hamburger"]'))) {
$hamburgerToggle.removeClass('is-active');
}
})
},
finalize() {
// JavaScript to be fired on all pages, after page specific JS is fired
},
},
finalize() {
// JavaScript to be fired on all pages, after page specific JS is fired
},
};
......@@ -4,73 +4,75 @@ library.add(faChevronRight, faSearch);
dom.watch();
export default {
init() {
init() {
const wisselenergie = window.wisselenergie
const url = wisselenergie.ajax_url;
const site_url = wisselenergie.site_url;
const page_name = wisselenergie.page_name;
const wpnonce = wisselenergie.nonce;
const $main = $('main.main');
const $categories = $('.faq-category');
const $searchBox = $('#keyword');
const $body = $('body');
const kudos_website = window.kudos_website
const url = kudos_website.ajax_url;
const site_url = kudos_website.site_url;
const page_name = kudos_website.page_name;
const wpnonce = kudos_website.nonce;
const $main = $('main.main .row');
const $categories = $('.faq-category');
const $searchBox = $('#keyword');
const $body = $('body');
// Search box type action
$searchBox.keyup(delay(function (e) {
let keywords = $(e.currentTarget).val();
let category = $categories.filter('.current').data('category');
ajaxRequest(category, keywords);
}, 500));
// Search box type action
$searchBox.keyup(delay(function (e) {
let keywords = $(e.currentTarget).val();
let category = $categories.filter('.current').data('category');
ajaxRequest(category, keywords);
}, 500));
// Category click action
$categories.each(function () {
$(this).click(function (e) {
e.preventDefault();
// Stop if current category
if($(e.currentTarget).hasClass('current')) {
return;
}
// Define input
let category = $(this).data('category');
let keywords = $('#keyword').val();
ajaxRequest(category, keywords);
});
$(this).click(function (e) {
e.preventDefault();
// Stop if current category
if ($(e.currentTarget).hasClass('current')) {
return;
}
// Define input
let category = $(this).data('category');
let keywords = $('#keyword').val();
ajaxRequest(category, keywords);
});
})
function ajaxRequest(category=null, keywords=null) {
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: {
action: 'get_questions',
nonce: wpnonce,
category: category,
keywords: keywords,
},
beforeSend: function() {
$body.addClass('ajax-loading');
$main.fadeTo(200, 0.5, 'linear');
history.pushState(null,null, site_url + '/' + page_name + '/' + (category ? category + '/' : '') )
},
success: function (response) {
$categories.removeClass('current');
$categories.filter('[data-category="'+ category +'"]').addClass('current')
$main.html(response);
$main.fadeTo(200, 1, 'linear');
$body.removeClass('ajax-loading');
},
})
function ajaxRequest(category=null, keywords=null)
{
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: {
action: 'get_questions',
nonce: wpnonce,
category: category,
keywords: keywords,
},
beforeSend: function () {
$body.addClass('ajax-loading');
$main.fadeTo(200, 0.5, 'linear');
history.pushState(null,null, site_url + '/' + page_name + '/' + (category ? category + '/' : ''))
},
success: function (response) {
$categories.removeClass('btn-outline-primary');
$categories.filter('[data-category="'+ category +'"]').addClass('btn-outline-primary');
$main.html(response);
$main.fadeTo(200, 1, 'linear');
$body.removeClass('ajax-loading');
},
})
}
function delay(fn, ms) {
let timer = 0
return function(...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
function delay(fn, ms)
{
let timer = 0
return function (...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
},
},
};
......@@ -8,9 +8,12 @@ $font-serif: "libre_baskervillebold", Arial, sans-serif;
$theme-colors: (
primary: #ff9f1c,
secondary: #2ec4b6,
tertiary: #f58d00,
tertiary: #3c6997,
);
$tertiary-light: #bbcfe4;
$light: #edf2f8;
$danger: #d72638;
$success: #09814a;
......@@ -29,10 +32,6 @@ $btn-transition: color 0.6s ease;
// Modal
$modal-content-border-radius: 0;
/** Bootstrap navbar fix (https://git.io/fADqW) */
$navbar-dark-toggler-icon-bg: none;
$navbar-light-toggler-icon-bg: none;
/** Hamburger icon */
$hamburger-padding-x: 0;
$hamburger-padding-y: 0;
......
body.template-faq {
.top-banner {
overflow: hidden;
&::before {
content: "";
opacity: 0.2;
position: absolute;
background-image: url("../images/logo-white.svg");
background-repeat: no-repeat;
width: 375px;
height: 300px;
bottom: -100px;
right: 0;
transform: rotate(-30deg);
}
}
#keyword-group .search-icon {
position: absolute;
left: 0.5em;
left: 1em;
top: 50%;
z-index: 4;
transform: translateY(-50%);
}
input#keyword {