Skip to content

Instantly share code, notes, and snippets.

View rodrigoea's full-sized avatar
🏠
Working from home

Rodrigo Antinarelli rodrigoea

🏠
Working from home
View GitHub Profile
@rodrigoea
rodrigoea / functions.php
Created August 26, 2014 18:50
How to get submenu items from a WordPress menu based on parent or sibling
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
// find the current menu item
foreach ( $sorted_menu_items as $menu_item ) {
@rodrigoea
rodrigoea / count.html
Last active August 29, 2015 14:05
Show number of comments from Disqus
<a href="#disqus_thread"><span class="show-comments" data-disqus-url="CURRENT_URL">0 Comentários</span></a>
@rodrigoea
rodrigoea / gist:de0ea52ac5227fe88a19
Created August 28, 2014 14:09
Show Youtube title, description and views count with PHP
<?php
$youtube_id = 'JmRRawnSJEs';
$json_output = file_get_contents("http://gdata.youtube.com/feeds/api/videos/${youtube_id}?v=2&alt=json");
$json = json_decode($json_output, true);
//This gives you the video description
$video_description = $json['entry']['media$group']['media$description']['$t'];
//This gives you the video views count
$view_count = $json['entry']['yt$statistics']['viewCount'];
@rodrigoea
rodrigoea / gist:e12a2bf8a7309d2fd65e
Last active October 19, 2015 01:32
How to use the simple and perfect Deployment Workflow with Git and SSH ~ Automated Deploy (Bitbucket)

#Learn how to use the simple and perfect Deployment Workflow with Git and SSH

###Requirements

  • Bitbucket Account (You can also use Github or other GIT service).
  • SSH access to the publishing server
  • Have tool git installed on the local environment and server

ro ##Step 1 - Create a local git repo

@rodrigoea
rodrigoea / fields.php
Last active August 29, 2015 14:06
Dynamic Custom Fields With Custom Metaboxes - Wordpress
//download
$meta_boxes[] = array(
'id' => 'meta_marcas_downloads',
'title' => 'Downloads',
'pages' => array( 'qd_marcas' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
@rodrigoea
rodrigoea / gist:72b73ae5393be74f7e3b
Created October 1, 2014 17:14
Cut text after a number of characters and after the last point.
$text = "Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus.";
$split = strpos($text, '. ', 10)+1;
$text1 = wpautop(substr($text, 0, $split));
$text2 = wpautop(substr($text, $split));
@rodrigoea
rodrigoea / gist:5cedebdc9e0ffb928b21
Created October 2, 2014 17:28
Show current date in PHP (Portuguese)
class myDate{
var $myDate;
function theDate ()
{
setlocale (LC_ALL, 'pt_BR');
$this->myDate = strftime ("%A, %d de %B de %Y");
return $this->myDate;
}
}
@rodrigoea
rodrigoea / readme.md
Last active August 29, 2015 14:07
Follow Back Twitter Script using jQuery

#Easily follow back your twitter followers using jQuery

Make sure that you are signed in twitter.

  • Go to Twitter followers page.

    • Go down the scrolling until all followers are loaded.
  • Open Developer Tools.

    • Google Chrome
@rodrigoea
rodrigoea / gist:c853a1f89156147fd93c
Created November 10, 2014 18:58
Show bubble notification in Wordpress Menu
add_filter( 'add_menu_classes', 'show_pending_number');
function show_pending_number( $menu ) {
$type = "post_type";
$status = "draft";
$num_posts = wp_count_posts( $type, 'readable' );
$pending_count = 0;
if ( !empty($num_posts->$status) )
$pending_count = $num_posts->$status;
// build string to match in $menu array
@rodrigoea
rodrigoea / gist:3a93c31d6de4416b65da
Last active June 7, 2016 21:52
Open a file in Sublime Text via Terminal (osx)
  • Open terminal, paste the line below and press enter:

Sublime

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Atom

ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom