Skip to content

Instantly share code, notes, and snippets.

@dn7734
Created November 2, 2015 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dn7734/28322207e4cafc748621 to your computer and use it in GitHub Desktop.
Save dn7734/28322207e4cafc748621 to your computer and use it in GitHub Desktop.
wordpress sage function.php
<?php
/**
* Sage includes
*
* The $sage_includes array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*
* Please note that missing files will produce a fatal error.
*
* @link https://github.com/roots/sage/pull/1042
*/
$sage_includes = [
'lib/utils.php', // Utility functions
'lib/init.php', // Initial theme setup and constants
'lib/wrapper.php', // Theme wrapper class
'lib/conditional-tag-check.php', // ConditionalTagCheck class
'lib/config.php', // Configuration
'lib/assets.php', // Scripts and stylesheets
'lib/titles.php', // Page titles
'lib/extras.php', // Custom functions
];
foreach ($sage_includes as $file) {
if (!$filepath = locate_template($file)) {
trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
}
require_once $filepath;
}
unset($file, $filepath);
require_once('wp_bootstrap_navwalker.php');
if( function_exists('acf_add_options_page') ) {
$page = acf_add_options_page(array(
'page_title' => 'BlueSky Options',
'menu_title' => 'BlueSky Options',
'menu_slug' => 'bluesky-options-settings',
'capability' => 'edit_posts',
'position' => 1.1,
'redirect' => false
));
}
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_image_size( 'square-img', 300, 300, true); // name, width, height, crop
add_image_size( 'vertical-img', 335, 694, true);
add_image_size( 'horizontal-img', 594, 287, true);
add_image_size( '1x1-img', 600, 600, true);
add_image_size( '1x2-img', 300, 611, true);
add_image_size( '2x1-img', 600, 300, true);
add_image_size( '2x2-img', 600, 600, true);
add_image_size( '3x2-img', 900, 600, true);
add_image_size( 'blog-post', 2000, 400, true);
add_image_size( 'blog-post-2by1', 2000, 500, true);
add_filter('image_size_names_choose', 'my_image_sizes');
}
function my_image_sizes($sizes) {
$addsizes = array(
"square-img" => __( "Square image"),
"1x1-img" => __( "Square Small image"),
"1x2-img" => __( "Vertical Small image"),
"2x1-img" => __( "Horizontal Small image"),
"2x2-img" => __( "Square Large image"),
"3x2-img" => __( "Horizontal Large image"),
"3x2-img" => __( "blog-post"),
"blog-post-2by1" => __( "Two By One"),
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}
function my_js_variables(){ ?>
<script type="text/javascript">
var mft_load_more_ajax = {"ajaxurl":"<?php echo admin_url('admin-ajax.php'); ?>"};
</script><?php
}
add_action ( 'wp_head', 'my_js_variables' );
function mft_load_more_ajax() {
if( ! wp_verify_nonce($_POST['nonce'], 'mft_load_more_ajax'))
return;
$offset = $_POST['offset'];
$init_offset = $_POST['init_offset'];
if($offset != NULL && absint($offset) && $init_offset != NULL && absint($init_offset)) {
// Finally, we'll set the query arguments and instantiate WP_Query
$query_args = array(
'post_type' => array('post', 'project'),
'category_not_in' => array( 3, 6, 7 ),
'posts_per_page' => $init_offset,
'offset' => $offset
);
$post_list = array();
$i = 0;
$custom_query = new WP_Query ( $query_args );
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
$value = get_field( "image_layout" );
if ($value != '') {
$img_dimensions = strtolower($value) . '-img';
$valueClass = strtolower($value);
if ($value == '2x1') {
$valueClass = 'xs-6 sm-6 _2x1 twobyone';
} elseif ($value == '1x2') {
$valueClass = 'xs-6 sm-3 _1x2 onebytwo';
} elseif ($value == '2x2') {
$valueClass = 'xs-6 sm-6 _2x2 twobytwo';
} elseif ($value == '3x2') {
$valueClass = 'xs-6 sm-9 _3x2 threebytwo';
} else {
$valueClass = 'xs-6 sm-3 _1x1 onebyone';
}
} else {
$img_dimensions = '1x1-img';
$valueClass = 'xs-6 sm-3 _1x1 onebyone';
}
$image = get_field('home_grid_image');
$alt = $image['alt'];
$width = $image['sizes'][ $img_dimensions . '-width' ];
$height = $image['sizes'][ $img_dimensions . '-height' ];
$home_grid_image = $image['sizes'][ $img_dimensions ];
ob_start(); ?>
<article <?php post_class(array('grid-item hover-module', $valueClass, strtolower(get_field( "overlay_color" )))); ?>>
<a target="_blank" class="article-link " href='<?php the_permalink(); ?>' >
<div class="module-overlay <?php echo strtolower(get_field( "overlay_color" )); ?>"></div>
<img src="<?php echo $home_grid_image; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $alt; ?>" class="img-responsive image-hover__img--bw" />
<div class="hover__hover-content-container">
<div class="hover__hover-content--spacing">
<h2 class="primary-text-color heading--smallest text-primary"><?php the_title(); ?></h2>
</div>
</div>
<span class="filter-copy body-text__small-caps primary-text-color">
<div style="position: relative">
<i class="ion-android-add-circle text-primary icon"></i>
<i class="ion-android-arrow-dropright-circle text-primary icon"></i>
</div>
</span>
</a>
</article>
<?php
$post_list[$i] = ob_get_clean();
$i++;
}
echo json_encode($post_list);
} else {
echo json_encode(0);
}
}
die();
}
add_action( 'wp_ajax_mft_load_more_ajax', 'mft_load_more_ajax' );
add_action( 'wp_ajax_nopriv_mft_load_more_ajax', 'mft_load_more_ajax' );
/**
* Register `team` post type
*/
function team_post_type() {
// Labels
$labels = array(
'name' => _x("Team", "post type general name"),
'singular_name' => _x("Team", "post type singular name"),
'menu_name' => 'Team Profiles',
'add_new' => _x("Add New", "team item"),
'add_new_item' => __("Add New Profile"),
'edit_item' => __("Edit Profile"),
'new_item' => __("New Profile"),
'view_item' => __("View Profile"),
'search_items' => __("Search Profiles"),
'not_found' => __("No Profiles Found"),
'not_found_in_trash' => __("No Profiles Found in Trash"),
'parent_item_colon' => ''
);
// Register post type
register_post_type('team' , array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
) );
}
add_action( 'init', 'team_post_type', 0 );
/**
* Register `project` post type
*/
function project_post_type() {
// Labels
$labels = array(
'name' => _x("Project", "post type general name"),
'singular_name' => _x("Project", "post type singular name"),
'menu_name' => 'Projects',
'add_new' => _x("Add New", "project item"),
'add_new_item' => __("Add New Project"),
'edit_item' => __("Edit Project"),
'new_item' => __("New Project"),
'view_item' => __("View Project"),
'search_items' => __("Search Projects"),
'not_found' => __("No Projects Found"),
'not_found_in_trash' => __("No Projects Found in Trash"),
'parent_item_colon' => ''
);
// Register post type
register_post_type('project' , array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail', 'tags'),
'taxonomies' => array('post_tag')
) );
}
add_action( 'init', 'project_post_type', 0 );
/**
* Register `department` taxonomy
*/
function project_taxonomy() {
// Labels
$singular = 'Project Category';
$plural = 'Project Categories';
$labels = array(
'name' => _x( $plural, "taxonomy general name"),
'singular_name' => _x( $singular, "taxonomy singular name"),
'search_items' => __("Search $singular"),
'all_items' => __("All $singular"),
'parent_item' => __("Parent $singular"),
'parent_item_colon' => __("Parent $singular:"),
'edit_item' => __("Edit $singular"),
'update_item' => __("Update $singular"),
'add_new_item' => __("Add New $singular"),
'new_item_name' => __("New $singular Name"),
);
// Register and attach to 'team' post type
register_taxonomy( strtolower($singular), 'project', array(
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => false,
'labels' => $labels
) );
}
add_action( 'init', 'project_taxonomy', 0 );
/*
include_once( ABSPATH . 'wp-admin/includes/image.php' );
function regenerate_all_attachment_sizes() {
$args = array( 'post_type' => 'attachment', 'numberposts' => 100, 'post_status' => null, 'post_parent' => null, 'post_mime_type' => 'image' );
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
$file = get_attached_file( $post->ID );
wp_update_attachment_metadata( $post->ID, wp_generate_attachment_metadata( $post->ID, $file ) );
}
}
}
regenerate_all_attachment_sizes();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment