Mostrar botão curtir em post de WordPress segundo categoria

  • Autor Autor Alcarver
  • Data de início Data de início
Tradução em andamento: em alguns minutos este tópico estará em português. Por enquanto, o conteúdo está no original em espanhol. Ver original
Alcarver

Alcarver

Gamma
Verificación en dos pasos activada
Hola,

En mi blog con Thesis Theme estoy utilizando el siguiente código para mostrar el botón me gusta al principio y al final de cada post:

Inserir CODE, HTML ou PHP:
function fb_like() {
	if (is_single()) { ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php }
}
add_action('thesis_hook_after_post','fb_like');
add_action('thesis_hook_before_post','fb_like');

PERO hay una categoría (número 8) en la que quiero que se muestre el botón sólo al principio del post.

Una de las respuestas que me han dado es:

"You can create a condition (expand it) for the above that excludes from the above function && (!in_category('8')){ as described in the WP Codex on conditionals here. Then you could sort of do the reverse to get a function that says only if you are in category 8's posts then (same thing, different hook). You'd only use one add_action on that second function, since you only want the like before, but not after, the posts in that category."

😕

Soy más que novato en estos códigos y me están creciendo canas intentando hacerlo yo mismo.

Podéis ayudarme, Betas, por favor? :sorrow:
 
Foi útil? Participe da conversa

Com sua conta grátis você pode responder, mandar mensagem privada ao autor e comprar com Saldo retido: o pagamento é liberado quando você recebe o combinado.

Leva 30 segundos · você volta a este tópico ao terminar
MODO CORTO, NO SE SI WORDPRESS LO SOPORTARÁ:

PHP:
function fb_like() {
	if (is_single()) { ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php }
}

add_action('thesis_hook_after_post','fb_like');
 if( !is_category( 8 )):
add_action('thesis_hook_before_post','fb_like');
endif;


MODO QUE FUNCIONA SEGURO PERO MÁS EXTENSO:

PHP:
 fb_like2() {
	if (is_single()):{ ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php endif;
}

function fb_like() {
	if (is_single() && !is_category( 8 )): ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php endif;
}

add_action('thesis_hook_after_post','fb_like');
add_action('thesis_hook_before_post','fb_like2');

De todas formas hacer ésto desde functions.php es más engorroso que editar simplemente el theme y hacer la función allí, que funciona seguro y sería más corta.

¡Un saludo!
 
Gracias por la ayuda! :encouragement:

La primera opción no funcionó y la segunda lo hizo, pero tuve que cambiarle esta línea:

Inserir CODE, HTML ou PHP:
if (is_single() && !is_category( 8 )): ?>

por esta otra:

Inserir CODE, HTML ou PHP:
if (is_single() && !in_category( '8' )) { ?>

Al final, el código lo puse en custom_functions.php (con el Custom File Editor de Thesis Theme) y quedó así:

Inserir CODE, HTML ou PHP:
function fb_like2() {
	if (is_single()) { ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php }
}

function fb_like() {
 if (is_single() && !in_category( '8' )) { ?>
		<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php }
}
add_action('thesis_hook_after_post','fb_like');
add_action('thesis_hook_before_post','fb_like2');

Mil gracias, Bizleet!
 
Cierto, no me di cuenta del detalle. Para eso estamos, suerte.
 

Tópicos similares

Voltar
Topo