[post-tiles] or [post-tiles categories="1,2,4,10" posts="8" excerpt="18"]. Author: Ethan Hackett - TinCrate Version: 1.2.5 Author URI: http://www.tincrate.com/plugins Copyright (C) 2012 Ethan Hackett This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 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, see . */ // Checks to See Wordpress Version global $wp_version; // If it's not compatable with wordpress version 3.0 die and display message. if ( !version_compare($wp_version,"3.0",">=") ) { die("

You need at lease version 3.0 of Wordpress to use the TinCrate plugin.

Visit Wordpress.org to upgrade your current version of Wordpress."); } // Adds the function for the admin menu add_action('admin_menu', 'tc_post_tiles_menu'); // Creates the admin page and title function tc_post_tiles_menu() { add_options_page('Post Tiles', 'Post Tiles', 'manage_options', 'post-tiles-identifier', 'tc_post_tiles_options'); } // Adds function for declaring options add_action( 'admin_init', 'register_post_tiles_options' ); function register_post_tiles_options(){ // Registers Non Category Related Settings (it's outside the categories loop) register_setting( 'tc-plugin-settings', 'category-key'); register_setting( 'tc-plugin-settings', 'category-key-jquery'); register_setting( 'tc-plugin-settings', 'featured-images'); // Get all Post Categories $categories = get_categories(); //Loop Through Each Category foreach($categories as $category) { $cat_var = "cat_".$category->name; // Make lowercase $cat_var = strtolower($cat_var); $cat_var = str_replace(" ", "_", $cat_var); $cat = $category->name; // Creates a registered setting for each category. register_setting('tc-plugin-settings', $cat_var); } } // Adds the color picker add_action('init', 'load_theme_scripts'); function load_theme_scripts() { wp_enqueue_style( 'farbtastic' ); wp_enqueue_script( 'farbtastic' ); } function tc_post_tiles_options() { // Checks to make sure the viewer is the admin if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } // Start the page output // Get the plugin Url to attatch CSS and images etc. $plugin_url = plugins_url()."/post-tiles"; wp_enqueue_style( 'post-tiles', $plugin_url.'/post-tiles.css' ); wp_enqueue_script('post-tiles', $plugin_url.'/post-tiles.js' ); echo "
"; echo "

Post Tiles:

How to use Post Tiles:

  • 1.) To add posts tiles to a page or post copy and paste the following shortcode. Example: [post-tiles]
  • 2.) By default 8 posts are displayed. To change the amount of posts to display, use the posts=' ' attribute in the shortcode. Example: [post-tiles posts='10']
  • 3.) By default all post categories are called for the tiles. To specify the categories use the categories=' ' attribute separating them by commas. Example: [post-tiles categories='1,2,4']
  • NOTE: The category id numbers are listed below, next to the category names. You can use both the categories and posts attributes Example: [post-tiles categories='1,2,4' posts='8']
Example Post Title Here
Example post excerpt displayed below the title.

Pick Your Cutom Tile Colors:

1.) Click inside each of the category inputs.
2.) Next use the color picker on the left to select the color for that categories tiles.
3.) Save Your Changes
    "; // Define the settings for recording settings_fields('tc-plugin-settings'); // Retrieve additional options before the categories loop $show_key = get_option('category-key'); if(empty($show_key)){ $show_key = "false"; } $show_key_jquery = get_option('category-key-jquery'); if(empty($show_key_jquery)){ $show_key_jquery = "true"; } $featured_images_key = get_option('featured-images'); if(empty($featured_images_key)){ $featured_images_key = "false"; } // Get all Post Categories $categories = get_categories(); //Loops through each category and displays color inputs. foreach($categories as $category) { $cat_var = "cat_".$category->name; // Make lowercase $cat_var = strtolower($cat_var); $cat_var = str_replace(" ", "_", $cat_var); $cat = $category->name; $id = $category->cat_ID; // Retrieves option value $cat_var_value = get_option($cat_var); // Checks the value to see if it's empty. If it is use default. if (empty($cat_var_value)){ $cat_var_value = "#afe2f8"; } // Echo out each list Category Name > Id > Input echo "
  • ".$cat." (".$id.")
  • "; } ?>
  • value="true" /> On         value="false" /> Off   
    jQuery Category Sorting & Animation
    Turns the jQuery features on or off
  • value="true" /> Show    value="false" /> Hide
    Display the Category Key
    Show category names and colors ATTENTION: This featured requires jQuery be turned on'; ?>
  • value="true" /> On         value="false" /> Off   
    Use Featured Images For Tiles
    Uses the posts assigned featured image. ATTENTION: This featured requires jQuery be turned on'; ?>
  • '/>
'', 'posts'=>'', 'excerpt'=>''), $atts); // EXAMPLE USAGE: [post-tiles categories="1,2,3,4" posts="8"] // Defaults extract(shortcode_atts(array( "categories" => '', "posts" => '', "excerpt" => '' ), $atts)); // Configure Both Categories and Number of Posts For Query $excerpt_length = $atts['excerpt']; // Configure Categories For Query $cat_num = $atts['categories']; if (isset($cat_num)) { $cat_query = '&cat='.$atts['categories']; } // Configure Number of Posts For Query if empty use 8. $posts = $atts['posts']; if (isset($posts)) { $posts_query = 'posts_per_page='.$atts['posts']; } else { $posts_query = 'posts_per_page=50'; } // Configure Both Categories and Number of Posts For Query $the_query = $posts_query.$cat_query; // Run the query query_posts($the_query); // Reset and setup variables $output = ''; $temp_title = ''; $temp_link = ''; // Retrives The On/Off for jQuery $show_key_jquery = get_option('category-key-jquery'); // If jquery is on(true) then output the following if ($show_key_jquery == "true"){ // Get Plugin Url $plugin_url = plugins_url()."/post-tiles"; // Attatch Javascript echo ""; echo ""; // Add CSS ?> ID); $temp_link = get_permalink($post->ID); $temp_excerpt = get_the_excerpt($post->ID); // Check to see if the excerpt was not defined thus empty if ($excerpt_length == "") { // Set excerpt length to 19 as default. $excerpt_length = '19'; } // Truncates the excerpt length (Not using default wordpress for plugin conflicts) $words = explode(' ', $temp_excerpt); if (count($words) > $excerpt_length){ array_splice($words, $excerpt_length); $temp_excerpt = implode(' ', $words); $temp_excerpt .= '…'; } // Grabs the categories then assigns the first category in the string to the class. $category = get_the_category(); $category_name = $category[0]->cat_name; // Recovering Saved Color Values // Define the Settings for recording $cat_var = "cat_".$category_name; // Make lowercase $cat_var_value = strtolower($cat_var); $cat_var = str_replace(" ", "_", $cat_var); // Retrieve the option "hexadecimal value" for this category $cat_var_value = get_option($cat_var); // Checks the value to see if it's empty. If it is use default. if (empty($cat_var_value)){ $cat_var_value = "#afe2f8"; } // Retrieve the option feature image. $featured_images_key = get_option('featured-images'); // See if Featured image is true. // Clear features_style variable. $featured_style = ""; // Get the post ID. $theID = get_the_ID(); // If there is a featured image. if ($featured_images_key == "true") { if ( has_post_thumbnail()) { // Retrieve the featured image. $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium'); // Strip featured image down to the url. $url = $thumb['0']; $featured_style = "style='background: url(".$url.") 0 0;' class='featured-image'"; } } // Each output creates the li > link > title > exerpt $output .= "
  • $temp_title

    $temp_excerpt
  • \n"; // Each output_key creates a li > category color block > category name endwhile; else: $output .= "No posts available. Double check your the post-tiles shortcode, selected categories, and number of posts."; endif; // Reset the query so it doesn't interupt the normal query wp_reset_query(); // Display Key $show_key = get_option('category-key'); $show_key_jquery = get_option('category-key-jquery'); $featured_images_key= get_option('featured-images'); // If it's empty then the default value is false (default) if(empty($show_key)){ $show_key == "false"; } // If it's true then build the key. if ($show_key == "true"){ $ca_args = array( // $cat_num pulls from shortcode 'include' => $cat_num ); //List categories $categories = get_categories($ca_args); //Loops through each category and displays key and color. foreach($categories as $category) { // Set's category names $cat_var = $category->name; // Cleans up category names that have spaces $cat_var = str_replace(" ", "_", $cat_var); // Joins the cat_ with the category name to retrieve option $cat_var_key = "cat_".$cat_var; // Get's the category options which are the hexadecimal colors $cat_var_key_val = get_option($cat_var_key); // loops through the each category and prints them $key_items .= "".$cat_var."\n"; } // Creates the finished key $key_finished = "
    \n".$key_items."All
    \n\n"; } else { $key_finished = ""; } return $key_finished.''; $plugin_url = plugins_url()."/post-tiles"; } // Add the Scripts add_action('wp_enqueue_scripts', 'post_tiles_stylesheet'); // Adds CSS function post_tiles_stylesheet() { $plugin_url = plugins_url()."/post-tiles"; wp_enqueue_style( 'post-tiles', $plugin_url.'/post-tiles.css' ); // wp_enqueue_script('post-tiles', $plugin_url.'/post-tiles-frontend.js' ); } ?>