Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /* Template Name: All Icons */ ?>
- <?php get_header();?>
- <div class="col-xs-12">
- <div class="container">
- <h1 class="text-center"><?php the_title();?></h1>
- <div id="" class="container">
- <?php
- $string = file_get_contents("http://paulosaferreira.com/wp-content/themes/flipcard/json-files/noun-project-2016-May-24.json");
- $json_a = json_decode($string, true);
- foreach ($json_a as $icons => $icon) {
- $icon_post = array(
- 'post_title' => $icon['name'],
- 'post_type' => 'icon',
- 'post_status' => 'publish',
- 'post_author' => 1
- );
- //////////// FATURED IMAGE //////////////
- $post_id = wp_insert_post($icon_post);
- // Add Featured Image to Post
- $image_url = $icon['img'] ;// Define the image URL here
- $upload_dir = wp_upload_dir(); // Set upload folder
- $image_data = file_get_contents($image_url); // Get image data
- $filename = basename($image_url); // Create image file name
- // Check folder permission and define file location
- if( wp_mkdir_p( $upload_dir['path'] ) ) {
- $file = $upload_dir['path'] . '/' . $filename;
- } else {
- $file = $upload_dir['basedir'] . '/' . $filename;
- }
- // Create the image file on the server
- file_put_contents( $file, $image_data );
- // Check image file type
- $wp_filetype = wp_check_filetype( $filename, null );
- // Set attachment data
- $attachment = array(
- 'post_mime_type' => $wp_filetype['type'],
- 'post_title' => sanitize_file_name( $filename ),
- 'post_content' => '',
- 'post_status' => 'inherit'
- );
- // Create the attachment
- $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
- // Include image.php
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- // Define attachment metadata
- $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
- // Assign metadata to attachment
- wp_update_attachment_metadata( $attach_id, $attach_data );
- // And finally assign featured image to post
- set_post_thumbnail( $post_id, $attach_id );
- //////////// Custom Fields //////////////
- add_post_meta($post_id, 'icon_noun_id', $icon['id'] , true);
- $info_update_date = get_the_date( $format, $post_id );
- $downloads_update = "downloads_update";
- $value = array(
- array(
- "sample_date" => $info_update_date,
- "download_count" => $icon['downloads']
- )
- );
- update_field( $downloads_update, $value, $post_id );
- }
- ?>
- <?php
- $icons = array(
- 'post_type' => 'icon',
- 'post_status' => 'publish',
- 'order' => 'DESC', // 'ASC',
- 'posts_per_page' => -1
- );
- $icons = new WP_Query( $icons );
- ?>
- <?php if ( $icons->have_posts() ) : while ( $icons->have_posts() ) : $icons->the_post(); ?>
- <div class="icon-item" id="icon-id- <?php the_ID(); ?> ">
- <img src="<?php the_post_thumbnail_url('thumbnail' );?>" alt="Icon - <?php the_title();?>" class="icon-img">
- <h2><?php the_title(); ?></h2>
- <?php
- $iconID = 1;
- $download_update = get_field('downloads_update');
- // var_dump($download_update);
- echo '<br>';
- // echo $download_update['download_count'] ;
- $last_update_data = $download_update[count($download_update) - 1];
- $pervious_update_data = $download_update[count($download_update) - 2];
- $last_download_count = $last_update_data['download_count'];
- $pervious_download_count = $pervious_update_data['download_count'];
- $last_update_growth = $last_download_count - $pervious_download_count ;
- echo '<div class="download-count"> Total: '.$last_update_data['download_count'] . '</div>';
- echo '<div class="month-downloads"> This month: '. $last_update_growth . '</div>';
- echo '<div class="download-count"> '.$last_update_data['sample_date'] . '</div>';
- $iconID++;
- ?>
- </div> <!-- closes the first div box -->
- <?php endwhile;
- wp_reset_postdata();
- else : ?>
- <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
- <?php endif; ?>
- <?php get_footer();?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement