Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Add JavaScript files
- function add_scripts() {
- wp_enqueue_script('modernizr_script', get_template_directory_uri() . '/js/modernizr.js', __FILE__);
- wp_enqueue_script('global_functions_script', get_template_directory_uri() . '/js/global-functions.js', __FILE__);
- }
- add_action('wp_enqueue_scripts', 'add_scripts');
- // Setup and load the theme options page and related code
- require(get_template_directory() . '/inc/theme-options.php');
- //Get theme options
- $options = get_option('shv_theme_options');
- // Add support for custom backgrounds
- add_custom_background();
- // Add support for post thumbnails and admin bar
- add_theme_support('post-thumbnails');
- add_theme_support('admin-bar');
- // This theme uses wp_nav_menu() in two locations
- if (function_exists('register_nav_menus')) {
- register_nav_menus(array(
- 'primary' => 'Primary Navigation',
- 'secondary' => 'Secondary Navigation'
- ));
- }
- /*
- * Register custom post types
- */
- //Testimonials Post Type
- class SHV_Testimonials_Post_Type {
- //Create construct function
- public function __construct() {
- $this->register_post_type();
- $this->metaboxes();
- }
- //Register post type
- public function register_post_type() {
- $args = array(
- 'labels' => array(
- 'name' => 'Testimonials',
- 'singular_' => 'Testimonial',
- 'add_new' => 'Add New Testimonial',
- 'all_items' => 'All Testimonials',
- 'add_new_item' => 'Add New Testimonial',
- 'edit_item' => 'Edit Testimonial',
- 'new_item' => 'New Testimonial',
- 'view_item' => 'View Testimonial',
- 'search_items' => 'Search Testimonials',
- 'not_found' => 'No Testimonials Found',
- 'not_found_in_trash' => 'No Testimonials Found in Trash'
- ),
- 'query_var' => 'testimonials',
- 'rewrite' => array(
- 'slug' => 'testimonials',
- ),
- 'public' => true,
- 'supports' => array(
- 'title'
- )
- );
- register_post_type('shv_testimonials', $args);
- }
- //Build metaboxes
- public function metaboxes() {
- //Add new meta boxes testimonial and testimonial author
- add_action('add_meta_boxes', 'add_testimonial_meta_box');
- add_action('add_meta_boxes', 'add_testimonial_author_meta_box');
- //Run add_meta_box functions
- function add_testimonial_meta_box() {
- add_meta_box('shv_testimonial', 'Testimonial', 'testimonial', 'shv_testimonials');
- }
- function add_testimonial_author_meta_box() {
- add_meta_box('shv_testimonial_author', 'Testimonial Author', 'testimonial_author', 'shv_testimonials');
- }
- //Create form elements and pull through any data associated with each meta box
- function testimonial($post) {
- $testimonial = get_post_meta($post->ID, 'shv_testimonial', true); ?>
- <p>
- <label for="shv_testimonial">Please enter your testimonial</label>
- <textarea class="large-text" name="shv_testimonial" id="shv_testimonial" cols="50" rows="5"><?php echo esc_attr($testimonial); ?></textarea>
- </p>
- <?php }
- function testimonial_author($post) {
- $author = get_post_meta($post->ID, 'shv_testimonial_author', true); ?>
- <p>
- <label for="shv_testimonial_author">Please enter a testimonial author name and school, e.g. John Doe, St Ambrose Barlow</label>
- <input type="text" class="widefat" name="shv_testimonial_author" id="shv_testimonial_author" value="<?php echo esc_attr($author); ?>" />
- </p>
- <?php }
- //Save meta box input
- add_action('save_post', 'save_meta_data');
- function save_meta_data($id) {
- if (isset($_POST['shv_testimonial'])) {
- update_post_meta(
- $id,
- 'shv_testimonial',
- strip_tags($_POST['shv_testimonial'])
- );
- }
- if (isset($_POST['shv_testimonial_author'])) {
- update_post_meta(
- $id,
- 'shv_testimonial_author',
- strip_tags($_POST['shv_testimonial_author'])
- );
- }
- }
- }
- }
- add_action('init', 'register_testimonials');
- function register_testimonials() {
- new SHV_Testimonials_Post_Type();
- }
- function show_tweets() { ?>
- <img src="<?php echo get_bloginfo('template_directory') . '/images/twitter-bird-icon.png'; ?>" alt="Tweets" />
- <?php
- //Get theme options
- $options = get_option('shv_theme_options');
- include_once(ABSPATH . WPINC . '/feed.php');
- $username = $options['shv_twitter_username'];
- $rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=' . $username);
- if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
- // Figure out how many total items there are, but limit it to 5.
- $maxitems = $rss->get_item_quantity(1);
- // Build an array of all the items, starting with element 0 (first element).
- $rss_items = $rss->get_items(0, $maxitems);
- endif;
- ?>
- <ul>
- <?php if ($maxitems == 0) echo '<li>No items.</li>';
- else
- // Loop through each feed item and display each item as a hyperlink.
- foreach ( $rss_items as $item ) : ?>
- <li>
- <a href='<?php echo $item->get_permalink(); ?>'>
- <?php echo $item->get_title(); ?>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php }
- function show_testimonials() {
- $loop = new WP_Query(
- array(
- 'post_type' => 'shv_testimonials',
- 'order_by' => 'ID',
- )
- );
- if ($loop->have_posts()) {
- $output = '<ul class="testimonial-list">';
- while($loop->have_posts()) {
- $loop->the_post();
- $meta = get_post_meta(get_the_id(), '');
- print_r($meta);
- $output .= '
- <li>
- <a href="' . get_permalink() . '">
- ' . get_the_title() . ' | ' .
- $meta['shv_testimonial_author'][0] . '
- </a>
- </li>
- ';
- }
- }
- return $output;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement