Skip to content

Instantly share code, notes, and snippets.

@icemancast
Last active March 17, 2016 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icemancast/be9df1eb2b55a58920ac to your computer and use it in GitHub Desktop.
Save icemancast/be9df1eb2b55a58920ac to your computer and use it in GitHub Desktop.
function get_testimonies($count = 4) {
$args = array(
'post_type' => 'codeup-testimonies',
'post_status' => 'publish',
'posts_per_page' => $count,
'orderby' => 'rand'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$testimonies[] =
[
'id' => get_the_ID(),
'name' => get_the_title(),
'testimony' => get_the_content(),
'image' => get_field('photo'),
'jobinfo' => get_field('job_info')
];
endwhile;
return $testimonies;
}
<?php
/*
* Plugin Name: Codeup Testimonies
* Plugin URI: http://codeup.com
* Description: Testimonies from students
* Version: 1.0.0
* Author: Isaac Castillo
* Author URI: http://icastwork.com
* License: GPL2
/* Copyright 2014 Isaac Castillo (email : icemancast@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if(!defined('CODEUP_TESTIMONIES_DIR')) define('CODEUP_TESTIMONIES_DIR', dirname(__FILE__));
//Require files
require_once CODEUP_TESTIMONIES_DIR . '/includes/functions.php';
require_once CODEUP_TESTIMONIES_DIR . '/includes/codeup-testimonies-shortcodes.php';
function codeup_testimonies_posttype()
{
$labels = array(
'name' => 'Codeup Testimonies',
'singular_name' => 'Codeup Testimonies',
'menu_name' => 'Codeup Testimonies',
'name_admin_bar' => 'Codeup Testimonies',
'add_new' => 'Add New',
'add_new_item' => 'Add New Testimony',
'new_item' => 'New Codeup Testimonies',
'edit_item' => 'Edit Testimony',
'view_item' => 'View Testimony',
'all_items' => 'All Testimony',
'search_items' => 'Search Codeup Testimonies',
'parent_item_colon' => 'Parent Codeup Testimonies',
'not_found' => 'No testimony found.',
'not_found_in_trash' => 'No testimony found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-editor-quote',
'query_var' => true,
'rewrite' => array( 'slug' => 'codeup-testimonies' ),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'custom-fields', 'page-attributes' )
);
register_post_type( 'codeup-testimonies', $args);
}
add_action('init', 'codeup_testimonies_posttype' );
function codeup_testimonies_rewrite_flush() {
// First, we "add" the custom post type via the above written function.
// Note: "add" is written with quotes, as CPTs don't get added to the DB,
// They are only referenced in the post_type column with a post entry,
// when you add a post of this CPT.
codeup_testimonies_posttype();
// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'codeup_testimonies_rewrite_flush' );
//'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats'),
<?php
/*----------------------------------------------------------------------------*/
/* Testimonies process shortcode
/*----------------------------------------------------------------------------*/
add_shortcode( 'codeup_testimonies_section', 'codeup_testimonies_section', 10 );
function codeup_testimonies_section( $atts ) {
extract( shortcode_atts( array(
'heading' => '',
'count' => '',
), $atts) );
$count = (empty($count)) ? 4 : esc_html($count);
$output = '<h2>' . esc_html( $heading ) . '</h2>';
$testimonies = get_testimonies($count);
// print_r($testimonies);
$output .= '<div class="col8-span clear bottom-style">
<section class="quote-container">
<div class="quote-box">';
foreach($testimonies as $testimony):
$output .= '<div class="quote-single" data-person="' . $testimony["id"] . '">' . $testimony["testimony"] . '</div>';
endforeach;
$output .= '</div>
<div class="clear"></div>';
$output .= '<div class="quotes-people">';
$i = 1;
foreach($testimonies as $testimony):
$hide = ($i != 1) ? 'hide' : '';
$output .= '<div class="quote-person">
<span class="triangle ' . $hide . '"></span>
<div class="photo">
<a class="target-person" href="#" data-person-target="' . $testimony["id"] . '">
<img src="' . $testimony["image"]["sizes"]["profesor-profile"] . '"></a>
</div>
<p class="name">' . $testimony["name"] . '</p>
<p class="workplace">' . $testimony["jobinfo"] . '</p>
</div>';
$i++;
endforeach;
$output .= '</div>
</section>
</div>';
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment