Skip to content

Instantly share code, notes, and snippets.

View designbuildtest's full-sized avatar

designbuildtest

View GitHub Profile
@designbuildtest
designbuildtest / gist:e44a8ea6f4ef5277cfbb
Created February 15, 2015 19:27
Get attachment ID from URL (core WP function)
attachment_url_to_postid()
@designbuildtest
designbuildtest / gist:616125e8c7656c7d87c5
Last active August 29, 2015 14:15
Add Theme Support - Testimonials
add_theme_support( 'myplugin-testimonials' ); // functions.php
if ( function_exists('myplugin_testimonial_html') ) { myplugin_testimonial_html(); } // template file
// Order by MENU ORDER > ASC when displayed in an archive.
function rc_modify_query_get_design_projects( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'testimonial' ) ) {
$query->set('orderby', 'menu_order' );
@designbuildtest
designbuildtest / gist:2631c0ac1031cdc81dd6
Last active August 29, 2015 14:15
Custom Manage Testimonials view
// Remove default columns from manage view.
function myplugin_custom_manage_testimonial_columns( $columns ) {
unset( $columns['author'] );
unset( $columns['date'] );
$columns['description'] = __( 'Excerpt' );
//$columns['menu_order_testimonial'] = __( 'Order' );
return $columns;
}
add_filter( 'manage_edit-testimonial_columns', 'myplugin_custom_manage_testimonial_columns' );
// Register 'Testimonial' Custom Post Type
function myplugin_testimonial_post_type() {
$labels = array(
'name' => _x( 'Testimonials', 'Post Type General Name' ),
'singular_name' => _x( 'Testimonial', 'Post Type Singular Name' ),
'menu_name' => __( 'Testimonials' ),
'add_new_item' => __( 'Add New Testimonial' ),
'search_items' => __( 'Search Testimonials' ),
);
@designbuildtest
designbuildtest / gist:7d30f953fec0929b4f14
Created February 17, 2015 01:21
archive-testimonial.php
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="container none-page-content testimonials">
<h1><?php post_type_archive_title(); ?></h1>
<?php while ( have_posts() ) : the_post(); ?>
<blockquote>
@designbuildtest
designbuildtest / gist:222a0ae5194a1583c0ee
Created February 17, 2015 01:22
single-testimonial.php
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="container none-page-content testimonials">
<h1 class="capitalize"><?php echo get_post_type(); ?></h1>
<?php while ( have_posts() ) : the_post(); ?>
<blockquote>
@designbuildtest
designbuildtest / gist:253114936af7baa06491
Created February 17, 2015 01:26
Timely - Click to Call
if ( current_theme_supports( 'onehundred-call-to-action' ) ) {
function myplugin_call_to_action_customize_register($wp_customize) {
$wp_customize->add_section('call_to_action', array(
'title' => __('Call to Action Button', 'onehundred'),
'priority' => 25,
) );
$wp_customize->add_setting('myplugin_call_to_action_text', array(
@designbuildtest
designbuildtest / gist:c9174781cc755ac082ef
Created February 17, 2015 01:29
Page Orderby Manage Screen Column
$columns['menu_order'] = __( 'Order' );
case 'menu_order':
$order = $post->menu_order;
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
$value = get_post_meta( $post->ID, '_myplugin_include_in_menu', true );
@designbuildtest
designbuildtest / gist:10f89d2e0a354918e151
Created February 17, 2015 01:37
CPT Orberby Manage Column
function myplugin_custom_manage_affiliation_columns( $columns ) {
unset( $columns['author'] );
unset( $columns['date'] );
$columns['menu_order_affiliation'] = __( 'Order' );
return $columns;
}
add_filter( 'manage_edit-affiliation_columns', 'myplugin_custom_manage_affiliation_columns' );
@designbuildtest
designbuildtest / gist:be3cbbaeeb66e98a97cb
Created February 17, 2015 02:10
Exclude a Metabox when Page is nominated as page_on_front
function myplugin_include_in_menu_meta_box() {
// Assign the ID of the page we're attempting to edit to a variable.
if ( isset( $_GET['post'] ) ) { $post_id = $_GET['post']; }
elseif ( isset( $_POST['post_ID'] ) ) { $post_id = $_POST['post_ID']; }
// Display metabox if we're creating a new page or editing a page other than the Homepage.
$front_page = get_option('page_on_front');
if ( ! isset($post_id) || ($post_id != $front_page) ) {
add_meta_box( 'myplugin_include_in_menu', __( 'Include in Navigation' ), 'myplugin_include_in_menu_meta_box_callback', 'page', 'side', 'default' );
}