Skip to content

Instantly share code, notes, and snippets.

@besimhu
besimhu / Smooth Scroll.js
Last active August 29, 2015 14:17
Smooth scroll any hashtag link to their ID.
// Smooth scroll to content
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
var targetH = $(this.hash),
target = targetH.length ? targetH : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 60
@besimhu
besimhu / Pagination
Created March 15, 2015 15:02
You don't need a pagination plugin to handle pagination.
/**
* Wordpress Pagination
* http://codex.wordpress.org/Function_Reference/paginate_links
*/
<div class="pagination-wrap">
<?php
// pagination
global $wp_query;
$big = 999999999; // need an unlikely integer
@besimhu
besimhu / Header hide on scroll.js
Last active August 29, 2015 14:17
Hides header when you scroll down and shows when you scroll back up. The animation is handled through CSS. You can simply use a transform to move the navigation off screen.
function headerHide() {
// Hide Header on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('.header-global').outerHeight();
$(window).scroll(function(event){
didScroll = true;
@besimhu
besimhu / Sub-menu automation of interior menus.php
Last active August 29, 2015 14:17
It takes the main navigation and if there are any submenu items corresponding with the page, it will generate the navigation.
<?php
function submenu($menu, $returnParent = false) {
global $post;
$menu_items = wp_get_nav_menu_items($menu);
$menu_childs = array();
$menu_IDs = array();
$parent_item = 0;
@besimhu
besimhu / Sub navigation on children and grand children pages.php
Last active August 29, 2015 14:17
Generate navigation based off parent, no matter if you are viewing children or grand children pages.
<nav class="sub-menu-wrap">
<ul class="sub-menu">
<?php
$children = wp_list_pages('depth=1&title_li=&child_of='.$post->ID.'&echo=0');
$current_page = wp_list_pages('title_li=&include='.$post->ID.'&echo=0');
$grandparent=0;
if($post->post_parent):
$parent = wp_list_pages('title_li=&include='.$post->post_parent.'&echo=0');
$siblings = wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&exclude='.$post->ID.'&echo=0');
@besimhu
besimhu / Breadcrumbs.php
Last active August 29, 2015 14:17
Basic breadcrumbs
<?php
function the_breadcrumb() {
global $post;
$blog = '<li><a href="'.esc_url( home_url() ).'/blog/" ?>Blog</a></li>';
echo '<div class="breadcrumbs-wrap">';
echo '<ul class="breadcrumbs">';
if (is_category() ) {
echo '<li>';
the_category('');
@besimhu
besimhu / Wordpress child pages of parent.php
Last active August 29, 2015 14:17
Show child pages of parent, or if viewing child page, it will get all pages associated with parent.
<aside>
<nav class="page-sub-navigation">
<?php
// get child pages from post parent, otherwise
// get child pages from the current page being viewed, in most cases the parent
if ($post->post_parent) {
$page_list = wp_list_pages( 'title_li=&display=0&child_of='.$post->post_parent.'&echo=0' );
} else {
@besimhu
besimhu / Select Box Menu.php
Last active August 29, 2015 14:17
Sometimes a standard navigation just will not do, in that case we can use a select dropdown to rely on native phone UI.
<?php
/**
* Select Menu Menu Walker
* Add to functions.php file
*/
class SelectBox_Menu_Walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
@besimhu
besimhu / Mobile navigation overflow scrolling.scss
Last active June 14, 2016 22:16
Enable overflow scrolling on menus when they are fixed. This works best when you have a container that holds menu items. An unordered list will do just fine.
.mobile-navigation {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
overflow: auto;
-webkit-overflow-scrolling: touch;
}
@besimhu
besimhu / Enable or disable mobile touch scrolling.
Created March 15, 2015 06:59
Enable or disable touch scrolling on phones. This is only best for when you have a fixed menu that takes the view port view and does not scroll at all. See wiki for menu in action.
module.exports = function() {
var $nav = $('.nav-global'),
$toggle = $('.menu-trigger'),
$active_class = 'nav-active',
prevent_default = function(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;