Skip to content

Instantly share code, notes, and snippets.

View alandbh's full-sized avatar

Alan Vasconcelos alandbh

View GitHub Profile
@alandbh
alandbh / get-posts-by-term.php
Last active April 18, 2017 15:21
It get posts by taxomony terms. // Pega posts pela taxonomia
function feed_cidades($categoria) {
if ($categoria == '') {
$args = array (
'post_type' => 'cidades', //it can be other
'posts_per_page' => '-1'
//'post__not_in' => array($exclude)
);
@alandbh
alandbh / admin_style.php
Created December 7, 2016 13:00
Inject style tag in admin header in order to apply custom styles // Insere estilos no painel de administração com a tag style
/* --------------------------------
Insere estilos no painel de administração
Alan
------------------------------------ */
add_action('admin_head', 'custom_admin_styles');
@alandbh
alandbh / altera-galeria.php
Created August 5, 2016 14:26
Altera o HTML de saída das Galerias
/* ----------------
Altera o HTML de saída das galerias
Alan
----------------- */
add_filter('post_gallery', 'my_post_gallery', 10, 2);
@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