Skip to content

Instantly share code, notes, and snippets.

View yuriitaran's full-sized avatar

Yurii Taran yuriitaran

View GitHub Profile
@yuriitaran
yuriitaran / WP_Query to display content from custom post type object
Created October 24, 2017 19:45
WP_Query to display content from custom post type object
<?php $the_query = new WP_Query( array( 'post_type' => 'slider', 'order' => 'ASC' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<img src="<?php the_field('slide_image'); ?>" alt="<?php the_field('slide_title'); ?>" />
<?php the_field('slide_title'); ?>
<?php endwhile; ?>
@yuriitaran
yuriitaran / Link to WP post
Created October 24, 2017 20:54
A stupid reminder
<?php echo esc_url( get_permalink( $post ) ); ?>
@yuriitaran
yuriitaran / WP shortcode with variable
Last active October 24, 2017 22:58
WP shortcode with variable
<?php echo do_shortcode('['.get_field('custom_field_name').']'); ?>
<?php $the_query = new WP_Query( array( 'post_type' => 'post', 'order' => 'ASC' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'template-parts/page/content', 'front-page' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
@yuriitaran
yuriitaran / wp-query-ref.php
Created November 7, 2017 10:08 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@yuriitaran
yuriitaran / JQuery scroll to specific position
Last active November 7, 2017 12:37
JQuery scroll to specific position
$('html, body').animate({
scrollTop: ($('.sroll-to-element').first().offset().top)
},500);
// Scroll to Main content
$( '.scroll-to-content' ).click(function() {
$('html, body').animate({
scrollTop: ($('.homepage-main').first().offset().top)
},800);
});
@yuriitaran
yuriitaran / WP Theme Options
Last active November 7, 2017 12:37
WP Theme Options
/**
* Theme Options
*/
add_action('customize_register', function($wp_customize) {
/**
* Add Custom Logo
*/
$wp_customize->add_setting('logo_img');
@yuriitaran
yuriitaran / JQuery Starter functions
Last active November 9, 2017 14:45
JQuery Starter functions for WP theme
// Hide outline for all links
$('a').on('mousedown', function(){
$(this).css('outline', 'none');
});
// Scroll to Main content
$( '.scroll-to-content' ).click(function() {
$('html, body').animate({
scrollTop: ($('main').first().offset().top)
},800);
@yuriitaran
yuriitaran / WP: Display Post Tags ordered by ID
Created November 10, 2017 09:24
WP: Display Post Tags ordered by ID
// Display Post Tags ordered by ID
function show_post_tags_ordered_by_id($post_id) {
$args = array(
'orderby' => 'term_id',
);
$tags = wp_get_post_tags( $post_id, $args );
$html = '<div class="tags">';
foreach ( $tags as $tag ) {
$tag_link = get_tag_link( $tag->term_id );
/* functions.php */
// Create pagination
function foundation_pagination( $query = '' ) {
if ( empty( $query ) ) {
global $wp_query;
$query = $wp_query;
}
// required for static front-page pagination
if ( get_query_var('paged') ) {