Skip to content

Instantly share code, notes, and snippets.

@ivandoric
ivandoric / gist:11215420
Created April 23, 2014 13:35
wordpress: Get last child category ID
<?php
//Get all terms associated with post in taxonomy 'category'
$terms = get_the_terms(get_the_ID(),'category');
//Get an array of their IDs
$term_ids = wp_list_pluck($terms,'term_id');
//Get array of parents - 0 is not a parent
$parents = array_filter(wp_list_pluck($terms,'parent'));
@ivandoric
ivandoric / gist:11215439
Created April 23, 2014 13:36
wordpress: Get parent category of custom taxonomy in Wordpress
<?php $terms = get_the_terms( $post->ID , 'product-category' );
if ( $terms != null ){
foreach( $terms as $term ) {
if($term->parent == 0){
$theterm = $term->slug;
}
unset($term);
} }
?>
@ivandoric
ivandoric / gist:11215483
Created April 23, 2014 13:37
drupal: Example of EntityFieldQuery to make Flex slider in Drupal
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('status', 1)
->propertyCondition('type', array('slider_gornji'))
->propertyOrderBy('created', 'DESC')
->range(0, 5);
$result = $query->execute();
$nodes = node_load_multiple(array_keys($result['node']));
@ivandoric
ivandoric / gist:11215515
Created April 23, 2014 13:38
php: Alternate rows
<?php $class = ($x%2 == 0)? 'odd': 'even'; ?>
@ivandoric
ivandoric / gist:11215573
Created April 23, 2014 13:40
wordpress: Filter on post types with custom taxonomy in admin
<?php
//Add this to functions PHP
function pippin_add_taxonomy_filters() {
global $typenow;
// an array of all the taxonomyies you want to display. Use the taxonomy name or slug
$taxonomies = array('product-category');
// must set this to the post type you want the filter(s) displayed on
@ivandoric
ivandoric / gist:11215603
Created April 23, 2014 13:41
drupal: Print out user fields
<?php
/*use print_r($user_profile['field_name']); to check out the array */
/*Some examples of this method */
<li><?php print $user_profile['field_drzava']['#title'] ?>: <?php print $user_profile['field_drzava'][0]['#markup'] ?></li>
<li><?php print $user_profile['field_tel_']['#title'] ?> <?php print $user_profile['field_tel_'][0]['#markup'] ?></li>
<li><?php print $user_profile['field_fax_']['#title'] ?> <?php print $user_profile['field_fax_'][0]['#markup'] ?></li>
<li><?php print $user_profile['field_sjediste_firme_']['#title'] ?> <?php print $user_profile['field_sjediste_firme_']['#items'][0]['value'] ?></li
@ivandoric
ivandoric / gist:11215625
Created April 23, 2014 13:41
drupal: Get author user name from $uid
<?php
$username = $node->name;
print $username;
?>
@ivandoric
ivandoric / gist:11215642
Created April 23, 2014 13:42
drupal: If content type do something
<?php if($node->type=='node-type-name'){ ?>
@ivandoric
ivandoric / gist:11215689
Created April 23, 2014 13:43
wordpress: Title for custom Wordpress pages, that have special loops on them
<?php
$post_id = $wp_query->post->ID; // get post ID
?>
<h2><?php echo get_the_title($post_id); ?></h2>
/* If using WPML for translation then */
<h2><?php echo get_the_title(icl_object_id($post_id, 'page', false)); ?></h2>
@ivandoric
ivandoric / gist:11215702
Created April 23, 2014 13:44
sublime: Always use same indentation
Add this to Preferences - Settings user
"tab_size": 8,
"translate_tabs_to_spaces": true,
"auto_indent": true,
"detect_indentation": false