Skip to content

Instantly share code, notes, and snippets.

View samuelsimoes's full-sized avatar

Samuel Simões samuelsimoes

  • Appolus
  • Rio de Janeiro
View GitHub Profile
@samuelsimoes
samuelsimoes / gist:2596395
Created May 4, 2012 17:30
Função pra gerar uma lista a partir de uma taxonomia
<?php
function gerar_menu_taxonomia($taxonomia_nome){
$args = array('taxonomy' => $taxonomia_nome, 'parent' => '0');
$taxonomias = get_categories($args);
echo "<ul>";
foreach ($taxonomias as $taxonomia) {
echo "<li>";
echo "<a href='" . get_term_link($taxonomia, $taxonomia_nome) . "'>";
echo $taxonomia->name;
@samuelsimoes
samuelsimoes / gist:2661820
Created May 11, 2012 19:12
Gerando LI com as imagens que estão anexadas ao post no Wordpress
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1
);
$imagens_post = get_posts($args);
if ($imagens_post) {
foreach ($imagens_post as $attachment) {
@samuelsimoes
samuelsimoes / gist:2719135
Created May 17, 2012 14:05
Pequena função para retornar um array com as imagens anexadas ao post em questão
<?php
/* Função para pegar as imagens que estão anexadas ao post */
function pegar_post_imagens() {
$imagens = array();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
@samuelsimoes
samuelsimoes / gist:2787907
Created May 25, 2012 12:49
Registra e fila!!
<?php
if(!is_admin()){
/* Estilos */
wp_register_style('reset', get_bloginfo('template_directory') . "/reset.css", null);
wp_register_style('style', get_bloginfo('stylesheet_url'), array('reset'), null);
wp_register_style('font-lato', 'http://fonts.googleapis.com/css?family=Lato:300,400,700,400italic,700italic');
wp_enqueue_style('reset');
wp_enqueue_style('style');
wp_enqueue_style('font-lato');
@samuelsimoes
samuelsimoes / gist:2980808
Created June 24, 2012 00:54
Trabalhar com o JSON da API do Flickr com o PHP
<?php
$curl = curl_init();
// Atente para o nojsoncallback=1
curl_setopt($curl, CURLOPT_URL, 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&id=8418630@N03&nojsoncallback=1');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$resposta = curl_exec($curl);
// Corrige o problema do JSON inválido quando há uma aspa simples na legenda da foto
preg_match("/\\\'/", $resposta, $content);
@samuelsimoes
samuelsimoes / gist:3011642
Created June 28, 2012 14:19
Ajax no Wordpress. Faça do jeito certo!

#Ajax no Wordpress

###functions.php (ou arquivo incluído)

<?php

#Registra o seu script com o seu ajax no functions.php, no meu caso samuel.js
wp_register_script('samuel', get_bloginfo('template_directory') . "/scripts/samuel.js", array('jquery'));
@samuelsimoes
samuelsimoes / gist:3112811
Created July 14, 2012 19:12
Pegar o ID do Vídeo com PHP a partir da URL do Vídeo.
<?php
parse_str(parse_url($url_video_youtube, PHP_URL_QUERY), $parms_url_youtube);
$id_video_youtube = ($parms_url_youtube['v']) ? $parms_url_youtube['v'] : false;
@samuelsimoes
samuelsimoes / gist:3136540
Created July 18, 2012 14:33
Função mais apropriada para colocar no lugar do the_title no <title> do header.php no Wordpress
<?php
function custom_theme_title($separador=null, $sufixo=null){
global $post;
$title = "";
if(is_post_type_archive()) $title .= post_type_archive_title(null, false);
else if(is_page()) $title .= get_the_title($post_id);
else if(is_home()) $title .= 'Blog';
@samuelsimoes
samuelsimoes / gist:3828750
Created October 3, 2012 18:19
Comprimir arquivos via PHP
<?php
/**
* Comprimir um diretório no servidor usando PHP.
*
* A linha comentada é uma alternativa no caso da primeira
* não funcionar.
*/
var_dump(exec('zip -r backup.zip site/'));
//var_dump(exec('tar cjvfp backup.tar.bz2 site/'));
@samuelsimoes
samuelsimoes / gist:3833458
Created October 4, 2012 13:15
Deixando o Sublime Text no Windows parecido (em questão de atalhos) com o MacOS
[
{ "keys": ["alt+left"], "command": "move_to", "args": {"to": "bol", "extend": false} },
{ "keys": ["alt+right"], "command": "move_to", "args": {"to": "eol", "extend": false} },
{ "keys": ["alt+shift+left"], "command": "move_to", "args": {"to": "bol", "extend": true} },
{ "keys": ["alt+shift+right"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["alt+shift+p"], "command": "show_overlay", "args": {"overlay": "command_palette"} },
{ "keys": ["alt+shift+o"], "command": "file_navigator" },
{ "keys": ["alt+super+f"], "command": "show_panel", "args": {"panel": "replace"} },
{ "keys": ["alt+shift+c"], "command": "toggle_comment", "args": { "block": true } },
{ "keys": ["alt+super+right"], "command": "next_view" },