Last active
April 22, 2017 10:07
-
-
Save sixertoy/5fd44a72d89a7e076f08190b15d9402b to your computer and use it in GitHub Desktop.
Wordpress Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $args = array( | |
| 'order' => 'DESC', | |
| 'posts_per_page' => 10, | |
| 'post_type' => 'slides', | |
| 'post_status' => 'publish', | |
| ); | |
| $my_query = new WP_Query($args); | |
| ?> | |
| <!-- STARTOF #main --> | |
| <div id="main"> | |
| <div class="slides"> | |
| <?php if($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); | |
| $id = get_the_ID(); | |
| $imgSize = 'wide-size'; | |
| $dates = get_post_meta($id, 'slides_dates', true) || false; | |
| ?> | |
| <div class="item slide"> | |
| <figure class="item-cover"> | |
| <img src="<?php the_post_thumbnail_url($imgSize); ?>"> | |
| </figure> | |
| <h2> | |
| <span><?php the_title(); ?></span> | |
| <?php if ($dates) : ?> | |
| <span class="date"><?php echo $dates; ?></span> | |
| <?php endif; ?> | |
| </h2> | |
| </div> | |
| <?php endwhile; endif; ?> | |
| </div> | |
| </div> | |
| <!-- ENDOF #main --> | |
| <?php | |
| wp_reset_postdata(); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function get_post_vimeo_id ($url_teaser) { | |
| $regex = '/(http|https)?:\/\/(www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|)(\d+)(?:|\/\?)/'; | |
| preg_match($regex, $url_teaser, $ids); | |
| return $ids[4]; | |
| } | |
| function get_post_youtube_id ($url_teaser) { | |
| $regex = '/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"\'>]+)/'; | |
| preg_match($regex, $url_teaser, $ids); | |
| return $ids[5]; | |
| } | |
| ?> | |
| <!-- STARTOF #teaser --> | |
| <?php if (isset($teaser) && !empty($teaser)) : ?> | |
| <div class="teaser-wrapper"> | |
| <div class="teaser"> | |
| <?php if (strpos($teaser, 'vimeo') !== false) : ?> | |
| <?php $url = get_post_vimeo_id($teaser); ?> | |
| <?php $url = 'https://player.vimeo.com/video/'.$url.'?title=0&byline=0&portrait=0'; ?> | |
| <?php elseif (strpos($teaser, 'youtube') !== false) : ?> | |
| <?php $url = get_post_youtube_id($teaser); ?> | |
| <?php $url = 'https://www.youtube.com/embed/'.$url.'?rel=0'; ?> | |
| <?php endif; ?> | |
| <iframe | |
| src="<?php echo $url; ?>" | |
| width="100%" | |
| height="100%" | |
| frameborder="0" | |
| webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> | |
| </div> | |
| </div> | |
| <?php endif; ?> | |
| <!-- ENDOF #teaser --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Returns an array of image ID | |
| * @param [type] $shortcode [description] | |
| * @return [type] [description] | |
| */ | |
| function get_shortcode_pictures_ids ($shortcode) { | |
| preg_match('/\[gallery.*ids=.(.*).\]/', $shortcode, $ids); | |
| $valid = $ids && is_array($ids) && !empty($ids); | |
| if (!$valid) { | |
| return array(); | |
| } | |
| $array_id = explode(",", $ids[1]); | |
| return $array_id; | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function my_theme_styles () { | |
| $slug = 'my_theme'; | |
| $path = (get_template_directory_uri() . '/style.css'); | |
| wp_register_style($slug, $path, array(), '1.0', 'all'); | |
| // Enqueue it! | |
| wp_enqueue_style($slug); | |
| } | |
| function my_theme_scripts () { | |
| $theme = 'my_theme'; | |
| $path = (get_template_directory_uri() . '/js/scripts.js'); | |
| wp_enqueue_script($theme, $path, array(), '1.0', 'all'); | |
| } | |
| add_action('wp_enqueue_scripts', 'my_theme_styles'); | |
| add_action('wp_enqueue_scripts', 'my_theme_scripts'); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Remove gallery shortcode form content | |
| * [gallery ids="5,6,7,8"]- | |
| * @param $types - embed|wp_caption|caption|gallery|playlist|audio|video | |
| */ | |
| function get_post_raw_content ($types='') { | |
| // $shortcode_regex = get_shortcode_regex(); | |
| $shortcode_regex = array( | |
| '\[(\[?)(gallery)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)' | |
| ); | |
| global $post; | |
| $content = get_the_content(); | |
| $pattern = join($types, $shortcode_regex); | |
| $content = preg_replace('/'. $pattern .'/s', '', $content); | |
| return $content; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment