Skip to content

Instantly share code, notes, and snippets.

View alandbh's full-sized avatar

Alan Vasconcelos alandbh

View GitHub Profile
@alandbh
alandbh / has_term.php
Last active April 21, 2017 00:53
If has term. Verifica se o post atual (dentro do loop) possui uma taxonomia associada.
if( has_term( 'jazz', 'genre' ) ) {
// do something
}
// ou
has_term( $term, $taxonomy, $post );
//https://codex.wordpress.org/Function_Reference/has_term
@alandbh
alandbh / combo_dinamico.html
Created June 10, 2016 04:24 — forked from ografael/combo_dinamico.html
Carregar combo com JQuery - Cidades e Estados
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.getJSON('estados_cidades.json', function (data) {
@alandbh
alandbh / insert_post_from_front_end.php
Created June 7, 2016 01:13
Inserção de post (ou custom post) via frontend
<?php
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
$postTitleError = '';
if ( isset( $_POST['submitted'] ) ) {
if ( trim( $_POST['postTitle'] ) === '' ) {
@alandbh
alandbh / blog_query_pagination.php
Last active August 1, 2016 20:27
Loop posts com wp_query. Serve para outros tipos
<?php
/*
Query posts de blog com paginação e com primeiro post diferenciado
Usado em Gamarra
Alan
*/
// WP_Query arguments
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
@alandbh
alandbh / the_time.php
Created March 2, 2016 02:24
Imprime a data no formato brasileiro. Ex: 2 de março de 2016 date time
<?php the_time('j \d\e F \d\e Y') ?>
@alandbh
alandbh / thumbnail.php
Created February 26, 2016 19:49
Imprime um thumbnail no tema e coloca uma classe específica no elemento <img>. Ex.: "img-responsive" ou "alignleft"
// se for um post
echo get_the_post_thumbnail( $post_id, 'thumbnail', array( 'class' => 'alignleft' ) );
//Se for uma página
echo get_the_post_thumbnail( $page->ID, 'full', array( 'class' => 'img-responsive' ) );
@alandbh
alandbh / is_child.php
Created February 23, 2016 20:10
Checa se a página atual é uma subpágina ou filha // check if current page is a subpage
/*
CHECA SE A PAGINA É FILHA
*/
function is_child() {
global $post; // if outside the loop
if ( is_page() && $post->post_parent ) {
return true; // This is a subpage
@alandbh
alandbh / shortcode_unautop.php
Created February 23, 2016 19:32
Retira os parágrafos e quebras de linha automáticos dos conteúdos dos shortcodes removes auto paragraphs an BRs inside shortcodes
/*
RETIRA OS PARÁGRAFOS E <BR> NOS CONTEÚDOS DOS SHORTCODES
*/
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'shortcode_unautop',100 );
@alandbh
alandbh / shortcode.php
Created February 23, 2016 19:29
Shortcode
// Shortcode de botões
class short_botao {
function shortcode($atts, $content = null)
{
extract(shortcode_atts(array(
'classe' => '',
'id' => '',
'link' => '#'
), $atts));
@alandbh
alandbh / the_slug.php
Created February 23, 2016 19:27
Retorna o slug de cada pagina Returns the page slug
// para retornar o slug de cada pagina
function the_slug($echo=true){
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if( $echo ) echo $slug;
do_action('after_slug', $slug);
return $slug;
}