Skip to content

Instantly share code, notes, and snippets.

View RafaelFunchal's full-sized avatar

Rafael Funchal RafaelFunchal

View GitHub Profile
@RafaelFunchal
RafaelFunchal / WordPress get_excerpt
Created October 22, 2012 22:57
Função que limita a quantidade de caracteres do excerpt() do WordPress.
// Coloque o código abaixo no arquivo functions.php do seu tema. O número 80 é a quantidade de caracteres a exibir.
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 80);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
return $excerpt;
@RafaelFunchal
RafaelFunchal / is_user_logged_in()
Created November 22, 2012 17:43
Como usar a função is_user_logged_in() do WordPress.
<?php
// Caso o usuário esteja logado
if ( is_user_logged_in() ) :
?>
Aqui você coloca o seu conteúdo, normalmente é a função do WordPress
<?php the_content(); ?>
<?php
// Caso o usuário não esteja logado
else :
?>
@RafaelFunchal
RafaelFunchal / WP_Query()
Last active January 5, 2019 15:13
Como exibir apens posts de uma determinada categoria na sua página WordPress
<?php
// Documentação completa em http://codex.wordpress.org/Class_Reference/WP_Query
$args = array(
'cat' => 1, //ID da sua categoria
'posts_per_page ' => 4, // Número de posts a exibir
);
$novo_loop = new WP_Query( $args );
if ( $novo_loop->have_posts() ) : while ( $novo_loop->have_posts() ) : $novo_loop->the_post();
@RafaelFunchal
RafaelFunchal / Show attachments
Last active February 2, 2016 11:43
Show all post attachments
<?php
$attachment_args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => get_the_ID()
);
$attachments = get_posts( $attachment_args );
@RafaelFunchal
RafaelFunchal / Populando uma div com ajax
Last active December 16, 2015 10:18
Populando uma div com ajax usando o WordPress
<!--
Essa parte do código deve ser inserida no arquivo onde está o formulário.
-->
<script>
// Isso evitará que a página seja recarrega ao enviar o formulário
$('form').submit(function () {
return false;
});
// Quando o submit do formulário for clicado
$("#id-do-seu-botao").click( function() {
<?php
/*
* Plugin Name: Category Image Field
* Plugin URI: http://claudiosmweb.com/
* Description: Adds image field in category description.
* Version: 0.1
* Author: Claudio Sanches
* Author URI: http://claudiosmweb.com/
* License: GPLv2 or later
*/
// SmoothScroll for websites v1.2.1
// Licensed under the terms of the MIT license.
// People involved
// - Balazs Galambosi (maintainer)
// - Michael Herf (Pulse Algorithm)
(function(){
// Scroll Variables (tweakable)
<?php
/*
Enviar e-mail para o administrador se houver posts para revisão
Dicas do @GugaAlves (@tudoparawp):
- Adicionar link para enviar e-mail diretamente para o administrador;
- Incluir link para a edição do post no admin, facilitando a vida do admin que receber este email.
Dicas do Gustavo Bordoni (@webord):
- incluir na função o $post (objeto para WP_Query) para não ficar passando o $post_id a cada save;
# Sync fork with original repository
#
# Requires an "upstream" remote, pointing to original repo
# e.g. `git remote add upstream git@github.com:user/repo.git`
alias git-sync-fork="git fetch upstream; git checkout master; git merge upstream/master"
@RafaelFunchal
RafaelFunchal / BuddyPress redirect after login
Last active August 29, 2015 13:56
Redirect a BuddyPress member to a specific page after login
<?php
function redirect_after_login() {
if( is_user_logged_in() && bp_is_register_page() ) {
bp_core_redirect( get_option('home') . '/page-slug/' );
}
}
add_action( 'template_redirect', 'redirect_after_login', 1 );