Skip to content

Instantly share code, notes, and snippets.

View kostiantyn-petlia's full-sized avatar

Kostiantyn Petlia kostiantyn-petlia

  • Ukraine
View GitHub Profile
@kostiantyn-petlia
kostiantyn-petlia / WP: get someone post
Last active August 29, 2015 14:26
WP: get someone post (p=123)
query_posts('p=3547'); // - записи присвоен идентификатор, равный 3547.
if (have_posts()) : // - если есть вообще указанная запись.
while (have_posts()) : the_post(); // - начинаем традиционный цикл WordPress.
print '<div id="post-'; the_ID(); // - выводим ID записи и её класс.
print '"'; post_class(); print '>';
print '<h4>'. get_the_title(). '</h4>'; // - выводим заголовок.
print get_the_content(); // - выводим содержимое.
print '</div>';
endwhile;
endif;
@kostiantyn-petlia
kostiantyn-petlia / WP: get category name
Last active August 29, 2015 14:26
WP: get category name use slug
<?php
$idObj = get_category_by_slug('s_about');
$id = $idObj->term_id;
echo get_cat_name($id);
?>
<?php if ( have_posts() ) : query_posts('p=1');
while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php the_post_thumbnail(array(100, 100)); ?>
<?php endwhile; endif; wp_reset_query(); ?>
<?php wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>
//or
<?php wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 60,60 ), false, '' ); ?>
//or
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 300,300 ), false, '' ); echo $src[0]; ?>
//and
get_the_post_thumbnail( $id ); // без параметра $size
//For the latest blog post:
<?php query_posts('showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_post_thumbnail(); ?>
<?php endwhile; ?>
//For a thumbnail from a particular page (in this case id =7 ):
<?php query_posts('page_id=7'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_post_thumbnail(); ?>
//WordPress has a few useful options, you can get the homepage ID by using the following:
$frontpage_ID = get_option('page_on_front');
//or the Blog ID by using:
$blog_ID = get_option('page_for_posts');
function get_post_by_slug($slug, $post_type){
$posts = get_posts(array(
'name' => $slug,
'posts_per_page' => 1,
'post_type' => $post_type,
'post_status' => 'publish'
));
if( !$posts ) {
throw new Exception("NoSuchPostBySpecifiedID");
@kostiantyn-petlia
kostiantyn-petlia / WP: Advanced Custom Fields GoogleMap
Last active August 29, 2015 14:27
Render script for ACF GooglMap Field
//======================================================================================================================
// Google Maps Scripts <div id="acf-map" data-lat="12.345678" data-lng="12.345678"></div>
//======================================================================================================================
function render_map($map_div) {
// var
var lat = $map_div.attr('data-lat');
var lng = $map_div.attr('data-lng');
// coordinates to latLng
var latlng = new google.maps.LatLng(lat, lng);
// map Options
// get current taxonomy-slug in template taxonomy-{taxonomy}.php
$term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo $term->slug;
// get full info of taxonomy
$the_tax = get_taxonomy( get_query_var( 'taxonomy' ) );
echo $the_tax->labels->name;
// get taxonomy-type current
echo get_query_var('taxonomy');
@kostiantyn-petlia
kostiantyn-petlia / all_my_facebook_photos.html
Last active August 29, 2015 14:27 — forked from cbosco/all_my_facebook_photos.html
Simple "get all of my facebook photos" facebook JS SDK + Graph API example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Photos with Friends!</title>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script>
/**
* This is the getPhoto library
*/