WordPress: WP Category post list and qTranslate issues [SOLVED]

WP Category post list and qTranslate are two of the plugins I usually use when developing websites with WordPress.

When using both of them together, all different post titles are concatenated to one big title (which contains the titles in all languages concatenated).

To fix this, simply edit wp-content/plugins/wp-category-posts-list/includes/wp_cpl_output_get.php and change from:

/** Add up the actual permalink and post title */
                $post_output .= '<a href="' . get_permalink($post->ID) . '" title="' . __('Permalink to: ', 'wp-cat-list-itg') . $post->post_title . '" target="' . ((false == $op['open_in'])? '_blank' : '_self') . '">' . $post->post_title . '</a>';

to

if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
				$post->post_title = esc_html(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post->post_title));
			}
 
                /** Add up the actual permalink and post title */
                $post_output .= '<a href="' . get_permalink($post->ID) . '" title="' . __('Permalink to: ', 'wp-cat-list-itg') . $post->post_title . '" target="' . ((false == $op['open_in'])? '_blank' : '_self') . '">' . $post->post_title . '</a>';

And your titles will be displayed correctly in each language 🙂

Al compartir posts en facebook no salen las imagenes (thumbnails) [SOLUCIONADO]

Algo común cuando se usa el theme Twenty eleven de wordpress es que las imagenes de los posts no salen automáticamente al compartirlos en facebook. Vaya, que al poner el link a un post en el estado de facebook, éste no es capaz de leer las imagenes y mostrar el thumbnail.

Sin entrar en consideraciones técnicas, lo más simple es que instaléis el plugin Add Facebook Share Thumbnail Meta, lo activéis y… problema resuelto, solucionado 🙂

Si queréis leer más sobre este tema, podéis hacerlo, en inglés, aqui

WordPress: show excerpts in the category or tag view [SOLVED]

“I just want to only display the excerpt instead of the entire text of the post in the category / tag archives, how to achieve this?”. This is a common question of wordpress users.

Well, the fix is really simple. Go to your working theme directory and look for content.php (or sometimes archive.php). You should see something like:

<?php if (is_search()) the_excerpt(); else the_content(__('Read the rest of this entry &raquo;', '')); ?>

Or it might just be:

<?php if ( is_search() ) : // Only display Excerpts for Search ?>

Just change that to include the cases of displaying category archive (or tag archive), as in:

<?php if ( is_category() || is_tag() || is_date() || is_search() ) : // Only display Excerpts for Tag Archive, Date Archive, and Search ?>

Upload the file to your server and you’re ready to go 🙂

WP-COMFY: change post rotation interval [SOLVED]

Those of you who are using WP Comfy (aka Comfy Magazine) theme for wordpress might be wondering how to change post rotation time (interval) so that posts rotate more quickly or slowly.

Well, the fix is quite easy. Edit /wp-content/themes/wp_comfy/scripts/tabs.js, look for:

if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)

More slow rotation:

if (parseInt(this.automodeperiod)>1000 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)

Quicker rotation:

if (parseInt(this.automodeperiod)>100 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)

Play with the parameter value to achieve desired result!

wordpress: Ordenar archive.php por fecha con query_posts

Imagina que ya tienes en tu theme de wordpress un archivo llamado archive.php que se encarga de interpretar url’s del tipo http://www.tusitiowordpress.com/tag/tagX

¿Cómo hacer para que, además de mostrar los posts filtrados por el tag ‘tagX’, los ordene por fecha? (y no por otro criterio, como la categoría)

Fácil:
Edita tu archive.php y busca:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Y cámbialo por

<?php query_posts($query_string . '&orderby=date&order=DESC'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Nótese la presencia de la variable $query_string que nos mantiene la query que ya se hacía (filtrar por tag) a la que añadimos los parámetros de ordenación por fecha (orderby=date) y ordenación decreciente (order=DESC).

Para ver la lista de parámetros que la función query_posts acepta, puedes consultar el manual de la función query_posts.

UPDATE: ordenar y los sticky posts
Se pueden producir problemas con los post de tipo sticky (que salgan siempre en primer lugar). Si queremos ignorar los post sticky, procederemos asi en wordpress 3.1 o superior (nótese el parámetro ignore_sticky_posts=1):

<?php 
query_posts($querystring. '&orderby=date&order=DESC&ignore_sticky_posts=1' );?>

Y asi en wordpress anterior a 3.1:

<?php
$query = array(
    'post__not_in' => get_option('sticky_posts')
);
$queryObject = new WP_Query($querystring.'&orderby=date&order=DESC&'.$query);
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Y si tenemos instalado el plugin AStickyPostOrder (muy útil para algunos aspectos) y queremos ignorar los settings de AStickyPostOrder en archive.php procederemos asi (nótese el parámetro &aspo=vanilla)

<?php query_posts($query_string . '&orderby=date&order=DESC&aspo=vanilla'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

¿Veis por qué AMO wordpress? Esta gente ha pensado en todo 🙂

WordPress: where am I? is it the frontpage? [solved]

Some days ago I talked about knowing where I am in Drupal and knowing where I am in Jooml. I’ve received some mails asking how to know where i am in wordpress (am I in the frontpage? am I in a single post view?).

You can know this by using wordpress conditional tags.

For instance,

is_home() 
    When the main blog page is being displayed. This is the page which shows the time based blog content of your site, so if you've set a static Page for the Front Page (see below), then this will only be true on the Page which you set as the "Posts page" in Administration > Settings > Reading. 
 
is_front_page() 
    When the front of the site is displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the 'Settings > Reading ->Front page displays' is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to "A static page" and the "Front Page" value is the current Page being displayed. Note: this tag was added at Version 2.5. 
 
is_single() 
    When any single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages)

WordPress WP-Postviews en español [RESUELTO]

El plugin el plugin wp-postviews de wordpress permite mostrar en tu theme el número de lecturas de un determinado post, utilizando la función the_views();.

Si queréis añadir esta información a vuestros posts, podréis hacerlo con una línea del tipo:

// OJO! Dentro de 'the loop'
(leido <?php if(function_exists('the_views')) { the_views(); } ?>)

Y esto mostrará algo del tipo:
Leido 25 views

Nosotros queremos que el texto ‘views’ se muestre en español.

Para ello editamos /wp-content/plugins/wp-postviews/wp-postviews.php y buscamos este código:

### Function: Display The Post Views
function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
	$post_views = intval(post_custom('views'));
	$views_options = get_option('views_options');
	if ($always || should_views_be_displayed($views_options)) {
		$output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
		if($display) {
			echo apply_filters('the_views', $output);
		} else {
			return apply_filters('the_views', $output);
		}
	}
	elseif (!$display) {
		return '';
	}
}

Y lo cambiamos a esto:

### Function: Display The Post Views
function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
	$post_views = intval(post_custom('views'));
	$views_options = get_option('views_options');
	if ($always || should_views_be_displayed($views_options)) {
		$output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
		// Added the following line to change from 'views' to 'veces' -----------
		$output = str_replace('views','veces',$output);
                // ------------------------------------------------------------------
		if($display) {
			echo apply_filters('the_views', $output);
		} else {
			return apply_filters('the_views', $output);
		}
	}
	elseif (!$display) {
		return '';
	}
}

¡Y ya está!

WordPress Yoast SEO + wp_comfy theme + Category titles

If you are using Yoast SEO plugin for wordpress with WP_Comfy theme you will notice that title’s (<title> tag) are not working as expected. Despite your settings in Yoast WordPress SEO: Titles the titles are not showing what you want.

Follow these steps to make them work:

Changes in header.php

Edit your /wp-content/themes/wp-comfy/header.php and change:

tle><?php seotitles(); ?></title>

To:

tle><?php wp_title(''); ?></title>

Changes in CATEGORY TITLE’s

In my SEO titles settings page, and more precisely in the Taxonomies->Category->title template I set the rule to:

%%title%% | %%sitename%% - %%sitedesc%%

But it failed to show the titles like I wanted.

I decided to make a quick (and dirty) fix in order to make it work:
– Edit \wp-content\plugins\wordpress-seo\frontend\class-frontend.php. Look for:

} else if ( is_category() || is_tag() || is_tax() ) {
			$term = $wp_query->get_queried_object();
			$title = trim( wpseo_get_term_meta( $term, $term->taxonomy, 'title' ) );

And change it to:

} else if ( is_category() || is_tag() || is_tax() ) {
			$term = $wp_query->get_queried_object();
			//$title = trim( wpseo_get_term_meta( $term, $term->taxonomy, 'title' ) );
			$title = $title . '  | '.get_bloginfo('name').' - '.get_bloginfo('description');

And you are ready to go!

Widget para wordpress: mostrar los twitts favoritos de tu cuenta twitter

Basándome en elTwitter Widget para WordPress de Sean Spalding, he modificado ligeramente el código para que muestre únicamente los twitts favoritos de un determinado usuario.

El fuente es éste:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
Plugin Name: Twitter Widget Favoritos
Plugin URI: http://leccionespracticas.com/php/widget-para-wordpress-mostrar-los-twitts-favoritos-de-tu-cuenta-twitter/
Description: Muestra favoritos de twitter de un usuario (usa Javascript <a href="http://twitter.com/badges/which_badge">Twitter 'badge'</a>)
Version: 1.0.0
Author: Miguel Martin
Author URI: http://www.leccionespracticas.com
License: GPL
Basado en: Twitter Widget by Sean Spalding - http://seanys.com/2007/10/12/twitter-wordpress-widget/
 
This software comes without any warranty, express or otherwise, and if it
breaks your blog or results in your cat being shaved, it's not my fault.
 
*/
 
function widget_Twidget_Favoritos_init() {
 
	if ( !function_exists('register_sidebar_widget') )
		return;
 
	function widget_Twidget_Favoritos($args) {
 
		// "$args is an array of strings that help widgets to conform to
		// the active theme: before_widget, before_title, after_widget,
		// and after_title are the array keys." - These are set up by the theme
		extract($args);
 
		// These are our own options
		$options = get_option('widget_Twidget');
		$account = $options['account'];  // Your Twitter account name
		$title = $options['title'];  // Title in sidebar for widget
		$show = $options['show'];  // # of Updates to show
 
        // Output
		echo $before_widget ;
 
		// start
		//echo '<div id="twitter_div">'
        //      .$before_title.$title.$after_title;
		echo $before_title.$title.$after_title.'<div id="twitter_div">';
		echo '<ul id="twitter_update_list"></ul></div>
		      <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>';
		// Con esta linea buscamos TODOS los twitts de el usuario identificado por $account
		/*echo '<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$account.'.json?callback=twitterCallback2&amp;count='.$show.'"></script>';*/
 
		// Con esta linea buscamos los favoritos del usuario identificado por $account
		// http://api.twitter.com/1/favorites/bibliouz.json?callback=twitterCallback2&count=5
		echo '<script type="text/javascript" src="http://api.twitter.com/1/favorites/'.$account.'.json?callback=twitterCallback2&amp;count='.$show.'"></script>';
 
		// Con esta otra linea se filtra por $account y por $hashtag
		// http://search.twitter.com/search.json?q=%23HASHTAG+from:USERNAME
		// similar a (parámetro rpp final es el número de tweets qse muestran
		// http://search.twitter.com/search?q=&ands=&phrase=&ors=&nots=&tag=bibliotecas&lang=all&from=bibliouz&to=&ref=&near=&within=15&units=mi&since=&until=&rpp=5
        //$hashtag = '%23'.'listado';
		/*echo '<script type="text/javascript" src="http://search.twitter.com/search.json?q=listado+from:bibliouz"></script>';*/
 
 
 
		// echo widget closing tag
		echo $after_widget;
	}
 
	// Settings form
	function widget_Twidget_Favoritos_control() {
 
		// Get options
		$options = get_option('widget_Twidget_Favoritos');
		// options exist? if not set defaults
		if ( !is_array($options) )
			$options = array('account'=>'seanys', 'title'=>'Twitter Updates', 'show'=>'5');
 
        // form posted?
		if ( $_POST['Twitter-submit'] ) {
 
			// Remember to sanitize and format use input appropriately.
			$options['account'] = strip_tags(stripslashes($_POST['Twitter-account']));
			$options['title'] = strip_tags(stripslashes($_POST['Twitter-title']));
			$options['show'] = strip_tags(stripslashes($_POST['Twitter-show']));
			update_option('widget_Twidget_Favoritos', $options);
		}
 
		// Get options for form fields to show
		$account = htmlspecialchars($options['account'], ENT_QUOTES);
		$title = htmlspecialchars($options['title'], ENT_QUOTES);
		$show = htmlspecialchars($options['show'], ENT_QUOTES);
 
		// The form fields
		echo '<p style="text-align:right;">
				<label for="Twitter-account">' . __('Account:') . '
				<input style="width: 200px;" id="Twitter-account" name="Twitter-account" type="text" value="'.$account.'" />
				</label></p>';
		echo '<p style="text-align:right;">
				<label for="Twitter-title">' . __('Title:') . '
				<input style="width: 200px;" id="Twitter-title" name="Twitter-title" type="text" value="'.$title.'" />
				</label></p>';
		echo '<p style="text-align:right;">
				<label for="Twitter-show">' . __('Show:') . '
				<input style="width: 200px;" id="Twitter-show" name="Twitter-show" type="text" value="'.$show.'" />
				</label></p>';
		echo '<input type="hidden" id="Twitter-submit" name="Twitter-submit" value="1" />';
	}
 
 
	// Register widget for use
	register_sidebar_widget(array('Twitter-favoritos', 'widgets'), 'widget_Twidget_Favoritos');
 
	// Register settings for use, 300x200 pixel form
	register_widget_control(array('Twitter-favoritos', 'widgets'), 'widget_Twidget_control', 300, 200);
}
 
// Run code and init
add_action('widgets_init', 'widget_Twidget_Favoritos_init');
 
?>

Las instrucciones de instalación son de lo más simple:

1. Copiar el archivo superior (twitter-widget-favoritos.php) en /wp-content/plugins/widgets (si no existe la carpeta, la crearemos).
2. Activar el plugin en el menú plugins de wordpress
3. Añadir el widget a la barra lateral en el menú widgets de wordpress y rellenar el menú con el id del usuario (por ejemplo, bibliouz).

Lo he testeado y funciona a la perfección con el tema WP Comfy en wordpress 3.0.4

Podéis consultar La API de favoritos de twitter y la del statuses/user_timeline o a API de búsquedas para más detalles.

Si queréis saber más sobre la creación de widgets para wordpress podéis hacerlo en este sencillo manual

[SOLVED] An Unexpected HTTP Error occurred during the API request – wordpress 3

If you are getting this error in WordPress 3:
An Unexpected HTTP Error occurred during the API request

Edit your wp-includes/class-http.php

Search this:

$defaults = array(
			'method' => 'GET',
			'timeout' => apply_filters( 'http_request_timeout', 5),

And change it to:

$defaults = array(
			'method' => 'GET',
			'timeout' => apply_filters( 'http_request_timeout', 30),

Should work now 😉

If it does not:

Install Core control plugin
Head to it’s menu under Tools, Select the HTTP Access module, Save the page.
Head over to the new HTTP tab along the top of the page.

What transports is it using? Does it make a difference if you disable the currently active transport?

Usual transports are (ordered by priority of use):

PHP HTTP Extension	
cURL	
PHP Streams	
PHP fopen()	
PHP fsockopen()

Next to each transport you will find if they are Available or Not available.

If the cURL transport is the currently active one, Disable that. Should work now!
curl transport disabled wordpress core control

If it does not, refer to this post at wordpress.org