Skip to content

Instantly share code, notes, and snippets.

@sixertoy
Last active April 22, 2017 10:07
Show Gist options
  • Select an option

  • Save sixertoy/5fd44a72d89a7e076f08190b15d9402b to your computer and use it in GitHub Desktop.

Select an option

Save sixertoy/5fd44a72d89a7e076f08190b15d9402b to your computer and use it in GitHub Desktop.
Wordpress Snippets
<?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();
?>
<?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 -->
<?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;
}
?>
<?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');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment