. */ // 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'); register_setting( 'tc-plugin-settings', 'responsive-key'); register_setting( 'tc-plugin-settings', 'animation-style'); register_setting( 'tc-plugin-settings', 'posttiles-width'); register_setting( 'tc-plugin-settings', 'posttiles-height'); register_setting( 'tc-plugin-settings', 'featured-image-width'); register_setting( 'tc-plugin-settings', 'featured-image-height'); register_setting( 'tc-plugin-settings', 'excerpt-length'); register_setting( 'tc-plugin-settings', 'pagination-key'); // Get all Post Categories $categories = get_categories(); //Loop Through Each Category foreach($categories as $category) { // Get category slug incase of special characters $cat_slug = "cat_".$category->slug; // Creates a registered setting for each category. register_setting('tc-plugin-settings', $cat_slug); } } // 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:

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
'', 'posts'=>'', 'excerpt'=>''), $atts); // EXAMPLE USAGE: [post-tiles categories="1,2,3,4" posts="8"] // Defaults extract(shortcode_atts(array( "categories" => '', "posts" => '', "excerpt" => '' ), $atts)); // Get and set the excerpt length $excerpt_shortcode = $atts['excerpt']; if (isset($excerpt_shortcode)) { $excerpt_length = $excerpt_shortcode; } else { $excerpt_length = get_option('excerpt-length'); if(empty($excerpt_length)){ $excerpt_length = "12"; } } // Pagination starting point if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } // 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=4'; } // Configure Both Categories and Number of Posts For Query $the_query = $posts_query.$cat_query.'&paged='.$paged; // 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'); // Retrives The On/Off for jQuery $responsive_key = get_option('responsive-key'); // Retrieve Animation Style $animation_style = get_option('animation-style'); if(empty($animation_style)){ $animation_style = "up"; } // Retrieves Tile Width $posttiles_li_width = get_option('posttiles-width'); if(empty($posttiles_li_width)){ $posttiles_li_width = "175"; } $posttiles_width = $posttiles_li_width-20; // Retrieves Tile Height $posttiles_li_height = get_option('posttiles-height'); if(empty($posttiles_li_height)){ $posttiles_height = "175"; } $posttiles_height = $posttiles_li_height-20; // Retrieve Featured Image Height $featured_image_height = get_option('featured-image-height'); if(empty($featured_image_height)){ $featured_image_height = "250"; } // Retrieves Featured Image Width $featured_image_width = get_option('featured-image-width'); if(empty($featured_image_width)){ $featured_image_width = "250"; } ?> "; echo ""; // Add CSS ?> max_num_pages; // Fix the url leading slash // Get the url $url = get_permalink(); // get the last character of the url string either / or not $lastchar = substr( $url, -1 ); // if the last character is or isn't a / configure the pagination formating accordingly if ( $lastchar != '/' ){ $format = "/page/%#%"; } else { $format = "page/%#%"; } // If the total of pages is greater than one create the pagination if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); $pagination = paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => $format, 'current' => $current_page, 'total' => $total_pages, )); $pagination ="
".$pagination."
"; } else { $pagination = ""; } } else { $pagination = ""; } if ($pagination_key == "top") { $top_pagination = $pagination; } elseif ($pagination_key == "bottom") { $bottom_pagination = $pagination; } elseif ($pagination_key == "both") { $top_pagination = $pagination; $bottom_pagination = $pagination; } else { $top_pagination = $pagination; $bottom_pagination = $pagination; } // the loop if (have_posts()) : while (have_posts()) : the_post(); // Get Post Elements $temp_title = get_the_title($post->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; $category_slug = $category[0]->slug; // Recovering Saved Color Values // Define the Settings for recording $cat_var = "cat_".$category_slug; // 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(); // Get The Date $theDate = get_the_date(); // Reset featured image bottom border fix // There's a margin issue on responsive so this fixes the bottom gap with border $featured_border = "border-bottom: 3px solid ".$cat_var_value.";border-right: 2px solid ".$cat_var_value.";"; // 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(), array($featured_image_width,$featured_image_height)); // Strip featured image down to the url. $url = $thumb['0']; $featured_style = "style='background: url(".$url.") 0 0;' class='featured-image ".$animation_style." ".$cat_var."'"; } else { $featured_style = "class='".$cat_var."'"; } } // 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(); // If responsive it true add responsive class if ($responsive_key == "true") { $responsive = "class='responsive'"; } // 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; // Sets the slug $cat_slug = $category->slug; // Cleans up category names that have spaces $cat_var_key = "cat_".$cat_slug; // 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 '
    '.$top_pagination.$key_finished.''.$bottom_pagination.'
    '; $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' ); } ?>