Mostrando el enlace RSS de nuestros links

Cuando editamos nuestros links en el gestor de links de WP vemos que existen unas funciones avanzadas. Entre ellas est� “RSS URI” que nos permiten agregar el feed o el canal RSS del sitio al que enlazamos. Sin embargo, por alguna raz�n desconocida, no podemos mostrar esta info en el sidebar.

Es extra�o si consideramos que en el codex de wordpress vemos que dice:

RSS is a form of syndication, used to generate WordPress Feeds. When displaying RSS links, this is the option to display the RSS link next to the site link.

http://example.com/feed/

Para conseguir esta funcionalidad entonces debemos editar y modificar el archivo wp-includes/links.php. Proucramos hacer antes una copia de seguridad del archivo en cuesti�n.

El trozo de c�digo que buscamos es este:

function get_links($category = -1, $before = '', $after = '
',
$between = ' ', $show_images = true, $orderby = 'name',
$show_description = true, $show_rating = false,
$limit = -1, $show_updated = 1, $echo = true) {

global $wpdb;

$direction = ' ASC';
$category_query = "";
if ($category != -1) {
$category_query = " AND link_category = $category ";
}
if (get_settings('links_recently_updated_time')) {
$recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL ".get_settings('links_recently_updated_time')." MINUTE) >= NOW(), 1,0) as recently_updated ";
} else {
$recently_updated_test = '';
}
if ($show_updated) {
$get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";
}

$orderby=strtolower($orderby);
if ($orderby == '')
$orderby = 'id';
if (substr($orderby,0,1) == '_') {
$direction = ' DESC';
$orderby = substr($orderby,1);
}

switch($orderby) {
case 'length':
$length = ",CHAR_LENGTH(link_name) AS length";
break;
case 'rand':
$orderby = 'rand()';
break;
default:
$orderby = " link_" . $orderby;
}

if (!isset($length)) {
$length = "";
}

$sql = "SELECT link_url, link_name, link_image, link_target,
link_description, link_rating, link_rel $length $recently_updated_test $get_updated
FROM $wpdb->links
WHERE link_visible = 'Y' " .
$category_query;
$sql .= ' ORDER BY ' . $orderby;
$sql .= $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
//echo $sql;
$results = $wpdb->get_results($sql);
if (!$results) {
return;
}

$output = "";

foreach ($results as $row) {
if (!isset($row->recently_updated)) $row->recently_updated = false;
$output .= ($before);

if ($show_updated && $row->recently_updated) {
$output .= get_settings('links_recently_updated_prepend');
}

$the_link = '#';

if ( !empty($row->link_url) )
$the_link = wp_specialchars($row->link_url);
$rel = $row->link_rel;

if ($rel != '') {
$rel = " rel='$rel'";
}

$desc = wp_specialchars($row->link_description, ENT_QUOTES);
$name = wp_specialchars($row->link_name, ENT_QUOTES);

$title = $desc;

if ($show_updated) {
if (substr($row->link_updated_f,0,2) != '00') {
$title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) .')';
}
}

if ('' != $title) {
$title = " title='$title'";
}

$alt = " alt='$name'";

$target = $row->link_target;
if ('' != $target) {
$target = " target='$target'";
}

$output.= " $output.= $rel . $title . $target;
$output.= '>';

if (($row->link_image != null) && $show_images) {
if (strstr($row->link_image, 'http'))
$output.= "";
else // If it's a relative path
$output.= "link_image' $alt $title />";
} else {
$output.= $name;
}

$output.= '';

if ($show_updated && $row->recently_updated) {
$output.= get_settings('links_recently_updated_append');
}

if ($show_description && ($desc != '')) {
$output.= $between.$desc;
}
$output.= "$after\n";
} // end while

if($echo) {
echo $output;
} else {
return $output;
}

Y lo cambiamos por este otro


function get_links($category = -1, $before = '', $after = '
',
$between = ' ', $show_images = true, $orderby = 'name',
$show_description = true, $show_rating = false,
$limit = -1, $show_updated = 1, $echo = true) {

global $wpdb;

$direction = ' ASC';
$category_query = "";
if ($category != -1) {
$category_query = " AND link_category = $category ";
}
if (get_settings('links_recently_updated_time')) {
$recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL ".get_settings('links_recently_updated_time')." MINUTE) >= NOW(), 1,0) as recently_updated ";
} else {
$recently_updated_test = '';
}
if ($show_updated) {
$get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f ";
}

$orderby=strtolower($orderby);
if ($orderby == '')
$orderby = 'id';
if (substr($orderby,0,1) == '_') {
$direction = ' DESC';
$orderby = substr($orderby,1);
}

switch($orderby) {
case 'length':
$length = ",CHAR_LENGTH(link_name) AS length";
break;
case 'rand':
$orderby = 'rand()';
break;
default:
$orderby = " link_" . $orderby;
}

if (!isset($length)) {
$length = "";
}

$sql = "SELECT link_url, link_name, link_image, link_target,
link_description, link_rating, link_rel, link_rss $length $recently_updated_test $get_updated
FROM $wpdb->links
WHERE link_visible = 'Y' " .
$category_query;
$sql .= ' ORDER BY ' . $orderby;
$sql .= $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
//echo $sql;
$results = $wpdb->get_results($sql);
if (!$results) {
return;
}

$output = "";

foreach ($results as $row) {
if (!isset($row->recently_updated)) $row->recently_updated = false;
$output .= ($before);

if ($show_updated && $row->recently_updated) {
$output .= get_settings('links_recently_updated_prepend');
}

$the_link = '#';

if ( !empty($row->link_url) )
$the_link = wp_specialchars($row->link_url);
$rel = $row->link_rel;

if ($rel != '') {
$rel = " rel='$rel'";
}

$desc = wp_specialchars($row->link_description, ENT_QUOTES);
$name = wp_specialchars($row->link_name, ENT_QUOTES);

$title = $desc;

if ($show_updated) {
if (substr($row->link_updated_f,0,2) != '00') {
$title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) .')';
}
}

if ('' != $title) {
$title = " title='$title'";
}

$alt = " alt='$name'";

$target = $row->link_target;
if ('' != $target) {
$target = " target='$target'";
}

$output.= " $output.= $rel . $title . $target;
$output.= '>';

if (($row->link_image != null) && $show_images) {
if (strstr($row->link_image, 'http'))
$output.= "";
else // If it's a relative path
$output.= "link_image' $alt $title />";
} else {
$output.= $name;
}

$output.= '';

$link_rss = $row->link_rss;
if ($link_rss != '') {
$output.= "(RSS)";
}

if ($show_updated && $row->recently_updated) {
$output.= get_settings('links_recently_updated_append');
}

if ($show_description && ($desc != '')) {
$output.= $between.$desc;
}
$output.= "$after\n";
} // end while

if($echo) {
echo $output;
} else {
return $output;
}
}

En concreto lo que hemos cambiado es lo siguiente:

$sql = “SELECT link_url, link_name, link_image, link_target,
link_description, link_rating, link_rel, link_rss $length $recently_updated_test $get_updated
FROM $wpdb->links
WHERE link_visible = ‘Y’ ” .

y un poco m�s abajo…

$link_rss = $row->link_rss;
if ($link_rss != ”) {
$output.= “(RSS)“;
}

Es decir le hemos agregado el campo link_rss a la consulta y luego, si existe el RSS, lo hemos hecho visible.

Technorati tags: ,
Tutoriales

Posts relacionados:

  1. Editores para WordPress
  2. Extensión P2P para Firefox
  3. 8 Expresiones Regulares
  4. links for 2008-10-08
  5. links for 2008-10-11

blog comments powered by Disqus