Skip to content

Instantly share code, notes, and snippets.

@oneblackcrayon
Forked from r4nd1/functions.php
Created October 17, 2022 22:07
Show Gist options
  • Save oneblackcrayon/c63f99947515a8110824f594b82ff1f9 to your computer and use it in GitHub Desktop.
Save oneblackcrayon/c63f99947515a8110824f594b82ff1f9 to your computer and use it in GitHub Desktop.
Test #1
<?php
/*
Author: Zhen Huang
URL: http://themefortress.com/
This place is much cleaner. Put your theme specific codes here,
anything else you may want to use plugins to keep things tidy.
*/
/*
1. lib/clean.php
- head cleanup
- post and images related cleaning
*/
require_once('lib/clean.php'); // do all the cleaning and enqueue here
/*
2. lib/enqueue-style.php
- enqueue Foundation and Reverie CSS
*/
require_once('lib/enqueue-style.php');
/*
3. lib/foundation.php
- add pagination
*/
require_once('lib/foundation.php'); // load Foundation specific functions like top-bar
/*
4. lib/nav.php
- custom walker for top-bar and related
*/
require_once('lib/nav.php'); // filter default wordpress menu classes and clean wp_nav_menu markup
/*
5. lib/presstrends.php
- add PressTrends, tracks how many people are using Reverie
*/
require_once('lib/presstrends.php'); // load PressTrends to track the usage of Reverie across the web, comment this line if you don't want to be tracked
require_once('lib/options.php'); // load PressTrends to track the usage of Reverie across the web, comment this line if you don't want to be tracked
/**********************
Add theme supports
**********************/
if( ! function_exists( 'reverie_theme_support' ) ) {
function reverie_theme_support() {
// Add language supports.
load_theme_textdomain('reverie', get_template_directory() . '/lang');
// Add post thumbnail supports. http://codex.wordpress.org/Post_Thumbnails
add_theme_support('post-thumbnails');
//set_post_thumbnail_size(373, 239, true);
add_image_size('fd-lrg', 1024, 99999);
add_image_size('fd-med', 768, 99999);
add_image_size('fd-sm', 373, 239);
// rss thingy
add_theme_support('automatic-feed-links');
// Add post formats support. http://codex.wordpress.org/Post_Formats
add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));
// Add menu support. http://codex.wordpress.org/Function_Reference/register_nav_menus
add_theme_support('menus');
register_nav_menus(array(
'primary' => __('Primary Navigation', 'reverie'),
'additional' => __('Additional Navigation', 'reverie'),
'utility' => __('Utility Navigation', 'reverie')
));
// Add custom background support
add_theme_support( 'custom-background',
array(
'default-image' => '', // background image default
'default-color' => '', // background color default (dont add the #)
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
)
);
}
}
add_action('after_setup_theme', 'reverie_theme_support'); /* end Reverie theme support */
// create widget areas: sidebar, footer
$sidebars = array('Sidebar');
foreach ($sidebars as $sidebar) {
register_sidebar(array('name'=> $sidebar,
'id' => 'Sidebar',
'before_widget' => '<article id="%1$s" class="panel widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
$sidebars = array('Footer 1');
foreach ($sidebars as $sidebar) {
register_sidebar(array('name'=> $sidebar,
'id' => 'footer_1',
'before_widget' => '<article id="%1$s" class="widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h5>',
'after_title' => '</h5>'
));
}
$sidebars = array('Footer 2');
foreach ($sidebars as $sidebar) {
register_sidebar(array('name'=> $sidebar,
'id' => 'footer_2',
'before_widget' => '<article id="%1$s" class="widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h5>',
'after_title' => '</h5>'
));
}
$sidebars = array('Footer 3');
foreach ($sidebars as $sidebar) {
register_sidebar(array('name'=> $sidebar,
'id' => 'footer_3',
'before_widget' => '<article id="%1$s" class="widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h5>',
'after_title' => '</h5>'
));
}
// return entry meta information for posts, used by multiple loops, you can override this function by defining them first in your child theme's functions.php file
if ( ! function_exists( 'reverie_entry_meta' ) ) {
function reverie_entry_meta() {
echo '<span class="byline author">'. __('Written by', 'reverie') .' <a href="'. get_author_posts_url(get_the_author_meta('ID')) .'" rel="author" class="fn">'. get_the_author() .', </a></span>';
echo '<time class="updated" datetime="'. get_the_time('c') .'" pubdate>'. get_the_time('F jS, Y') .'</time>';
}
};
// Register Custom Post Type
function whatson() {
$labels = array(
'name' => _x( 'Activities', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Activity', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Activity', 'text_domain' ),
'name_admin_bar' => __( 'Activity', 'text_domain' ),
'archives' => __( 'Activity Archives', 'text_domain' ),
'parent_item_colon' => __( 'Parent Activity:', 'text_domain' ),
'all_items' => __( 'All Activities', 'text_domain' ),
'add_new_item' => __( 'Add New Activity', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Activity', 'text_domain' ),
'edit_item' => __( 'Edit Activity', 'text_domain' ),
'update_item' => __( 'Update Activity', 'text_domain' ),
'view_item' => __( 'View Activity', 'text_domain' ),
'search_items' => __( 'Search Activity', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into Activity', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Activity', 'text_domain' ),
'items_list' => __( 'Activities list', 'text_domain' ),
'items_list_navigation' => __( 'Activitie list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter Activities list', 'text_domain' ),
);
$args = array(
'label' => __( 'Activity', 'text_domain' ),
'description' => __( 'Latest Activity Post Type', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', ),
//'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'whatson', $args );
}
add_action( 'init', 'whatson', 0 );
// Register Custom Post Type
function custom_article() {
$labels = array(
'name' => _x( 'Articles', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Article', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Article', 'text_domain' ),
'name_admin_bar' => __( 'Article', 'text_domain' ),
'archives' => __( 'Article Archives', 'text_domain' ),
'parent_item_colon' => __( 'Parent Article:', 'text_domain' ),
'all_items' => __( 'All Articles', 'text_domain' ),
'add_new_item' => __( 'Add New Article', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Article', 'text_domain' ),
'edit_item' => __( 'Edit Article', 'text_domain' ),
'update_item' => __( 'Update Article', 'text_domain' ),
'view_item' => __( 'View Article', 'text_domain' ),
'search_items' => __( 'Search Article', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into Article', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Article', 'text_domain' ),
'items_list' => __( 'Articles list', 'text_domain' ),
'items_list_navigation' => __( 'Articles list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter Articles list', 'text_domain' ),
);
$args = array(
'label' => __( 'Article', 'text_domain' ),
'description' => __( 'Article Post', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'article', $args );
}
add_action( 'init', 'custom_article', 0 );
function patient() {
$labels = array(
'name' => _x( 'Patients', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Patient', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Patient', 'text_domain' ),
'name_admin_bar' => __( 'Patient', 'text_domain' ),
'archives' => __( 'Patient Archives', 'text_domain' ),
'parent_item_colon' => __( 'Parent Patient:', 'text_domain' ),
'all_items' => __( 'All Patients', 'text_domain' ),
'add_new_item' => __( 'Add New Patient', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Patient', 'text_domain' ),
'edit_item' => __( 'Edit Patient', 'text_domain' ),
'update_item' => __( 'Update Patient', 'text_domain' ),
'view_item' => __( 'View Patient', 'text_domain' ),
'search_items' => __( 'Search Patient', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into Patient', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Patient', 'text_domain' ),
'items_list' => __( 'Patients list', 'text_domain' ),
'items_list_navigation' => __( 'Activitie list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter Patients list', 'text_domain' ),
);
$args = array(
'label' => __( 'Patient', 'text_domain' ),
'description' => __( 'Latest Patient', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', ),
//'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'patient', $args );
}
add_action( 'init', 'patient', 0 );
// Set a "PATIENT" custom post type not show up on the website
function patient_redirect() {
global $wp_query;
// redirect from 'slideshow' CPT to home page
if ( is_archive('patient') || is_singular('patient') ) :
$url = get_bloginfo('url');
wp_redirect( esc_url_raw( $url ), 301 );
exit();
endif;
}
add_action ( 'template_redirect', 'patient_redirect', 1);
function the_excerpts($new_length = 55, $new_more = '...') {
add_filter('excerpt_length', function () use ($new_length) {
return $new_length;
}, 999);
add_filter('excerpt_more', function () use ($new_more) {
return $new_more;
});
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>' . $output . '</p>';
echo $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment