Skip to content

Instantly share code, notes, and snippets.

View morgyface's full-sized avatar

Dan morgyface

View GitHub Profile
@morgyface
morgyface / image_slider.php
Last active July 10, 2017 10:08
Image slider using ACF and Unslider
<!-- header -->
<?php
$rows = count( get_field('slider') );
if ( is_front_page() && ( $rows > 1 ) && !$phone ) {
$themefolder = get_bloginfo('template_directory');
echo '<link rel="stylesheet" type="text/css" href="' . $themefolder . '/css/unslider.css">' . PHP_EOL;
}
?>
<!-- slider -->
@morgyface
morgyface / posts-page-content.php
Last active July 13, 2017 15:58
WordPress | Content for your posts page
<?php
// If your title is within the header or another include
if ( is_home() ) {
$postspage = get_option('page_for_posts');
$postspagetitle = get_the_title( $postspage );
echo '<h1>' . $postspagetitle . '</h1>';
}
?>
<?php
@morgyface
morgyface / wp_refer.php
Created July 20, 2017 19:55
WordPress | Get the referring post
<?php
$referer = wp_get_referer(); // Get the full URL of the referring URL
$refer_postid = url_to_postid( $referer ); // Convert the URL into a post ID
if ( $refer_postid ) {
// If the conversion was successful we have an ID, let us get more details
$refer_title = get_the_title( $refer_postid ); // Get the post title
echo '<p>Thank you for your interest in the role; <a href="' . $referer . '">' . $refer_title . '</a>.</p>';
}
?>
@morgyface
morgyface / trimmed_excerpt.php
Last active January 30, 2018 16:21
WordPress | Trim the excerpt
<?php
$excerpt = get_the_excerpt();
$char_limit = 110;
$excerpt_stripped = strip_tags( $excerpt ); // Remove any tags using the strip_tags function.
$excerpt_length = strlen( $excerpt_stripped ); // Now lets count the characters so we can compare
if ( $excerpt_length > $char_limit ) { // Now work out if we need to trim the character length.
$offset = $char_limit - $excerpt_length; // This gives us a negative value.
$position = strrpos( $excerpt_stripped, ' ', $offset ); // This starts looking for a space backwards from the offset
$trimmed_excerpt = substr( $excerpt_stripped, 0, $position ); // Trim up until the point of the last space.
$last_character = substr( $trimmed_excerpt, -1 ); // Identify the last character of the newly trimmed excerpt
@morgyface
morgyface / useful_sass_mixins.scss
Last active August 21, 2018 10:24
Useful Sass Mixins
@mixin transition($transition-property, $transition-time, $method) {
// These two cover pretty much everything from 2008. Apart from IE 6-9. But fuck that prick of a browser.
-webkit-transition: $transition-property $transition-time $method; // Need this for Chrome pre-dating 2013 and Safari 3 - 6
transition: $transition-property $transition-time $method;
}
// Example use: @include transition(all, 0.5s, ease);
@mixin vertical-align($position) {
position: $position;
top: 50%;
@morgyface
morgyface / get_posts_odd_even.php
Created September 6, 2017 14:47
WordPress | Get Posts Odd or Even
<?php
$args = array(
'posts_per_page' => 5,
'post_type' => 'post'
);
$posts = get_posts( $args );
if ( $posts ) {
$counter = 1;
echo '<ul>';
foreach ( $posts as $post ) : setup_postdata( $post );
@morgyface
morgyface / radial.php
Created September 12, 2017 16:51
A simple-ish PHP/SVG/CSS Radial progress chart
<style>
div.goal-meter .progression {
transform: rotate(-90deg);
}
div.goal-meter .progression .meter {
stroke-linecap: round;
fill: none;
}
div.goal-meter .progression #face {
stroke: #EEE;
@morgyface
morgyface / cf7-bootstrap.php
Created September 15, 2017 16:17
Contact Form 7 Bootstrap structure
<div class="form-group">
<label for="your-name">Full name</label>
[text your-name id:your-name class:form-control placeholder "Your full name"]
</div>
<div class="form-group">
<label for="your-email">Email address</label>
[email* your-email id:your-email class:form-control placeholder "Enter email"]
</div>
<div class="form-group">
<label for="your-phone">Phone number</label>
@morgyface
morgyface / testimonial_carousel.php
Last active March 23, 2021 17:51
Testimonial carousel | Wordpress | ACF | Bootstrap
@morgyface
morgyface / parent_template.php
Created December 5, 2017 10:04
WordPress | If parent uses specific template
<?php
$current_id = get_the_ID();
$parent_id = wp_get_post_parent_id( $current_id );
$template = get_page_template_slug( $parent_id );
$template_filename = 'template-page.php'; // Change this to the template name
?>
<?php
if ( $template == $template_filename ) {
echo 'Yes, the parent post uses ' . $template_filename;