Bel
plugin, davvero utile, pensando di adottarlo sul mio
wordpress-site, ho scoperto che c'è un piccolo errorino a livello di sintassi, o, se di errore non si tratta, a me proprio non andava.
Comunque leggendo per bene il codice ho notato una cosa.
L'errore si riscontra su questa riga , trattasi di virgola superflua:
<?php
$categories = $wpdb->get_results("SELECT cat_ID, cat_name, FROM
Mi sono permesso dunque di modificare il codice, ovviamente senza toccare in alcun modo i tuoi
copyright e le licenze.
Ecco il codice modificato per rendere funzionante il plugin per tutti coloro che avessero riscontrato il mio problema:
Codice PHP:
<?php
function categories_autolink($text)
{
/*
Plugin Name: Categories Autolink
Version: 1.01
Plugin URI: http://www.centrostudilaruna.it/huginnemuninn/plugin-wordpress
Description: Wraps categories names in links
Author: Alberto Lombardo
Author URI: http://www.centrostudilaruna.it/huginnemuninn
Based on : Autolink by Chris Lynch http://www.planetofthepenguins.com
Copyright (c) 2007
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt
This file is part of WordPress.
WordPress is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Define the $wpdb to perform queries on the WP database */
global $wpdb;
/* Wrap spaces around the text - helps with regexp? */
$text = " $text ";
/* Set exceptions; will be developed in tollowing releases */
$exceptions = 'WHERE cat_name <> "Names"';
/* Load categories */
$categories = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories");
/* Loop through links */
foreach ($categories as $categoria)
{
/* create cat_urls */
$cat_urls = get_category_link($categoria->cat_ID);
/* Replace any instance of the cat_name with the cat_name wrapped in a HREF to link_url */
$text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$categoria->cat_name\b(?!:)(?![^<>]*?>)|imsU","<a href=\"$cat_urls\">$categoria->cat_name</a>" , $text);
}
/* Trim extraneous spaces off and return */
return trim( $text );
}
add_filter('the_content', 'categories_autolink', 18);
?>
Saluti, e ancora complimenti per il plugin.