Je reviens vers vous avez toujours le même bout de code que dans le topic : Convertir encodage des caractéres UTF8 et ISO8859-1
Actuellement le fichier Commentaire.php ressemble à çà
Mon problème, c'est qu'il affiche les commentaires de TOUS les blogs de Wordpress MU; hors je souhaite afficher uniquement les commentaires d'une dizaine de blog. Comment choisir uniquement certains blog ?
Voilà le code de commentaires.php :
- Code: Tout sélectionner
<?php
header('Content-Type: text/html; charset=iso-8859-1');
/* Ne tentez pas de créer ce fichier à la main !!! Lisez le fichier README.txt et lancez l'assistant d'instalaltion. */
// ** MySQL settings ** //
define('DB_NAME', 'xxx'); // The name of the database
define('DB_USER', 'xxx'); // Your MySQL username
define('DB_PASSWORD', 'xxx'); // ...and password
define('DB_HOST', 'xxx'); // 99% chance you won't need to change this value
define('DB_CHARSET', 'ISO-8859-1');
define('DB_COLLATE', '');
define('VHOST', 'no');
$base = '/';
// double check $base
if( $base == 'BASE' )
die( 'Problème avec le fichier wp-config.php - La variable $base est définie avec la constante BASE lorsuque vous utilisez les URLs comme "/" ou "/blogs/"! Merci de corriger cela!' );
// You can have multiple installations in one database if you give each a unique prefix
$table_prefix = 'wp_'; // Only numbers, letters, and underscores please!
// Change this to localize WordPress. A corresponding MO file for the
// chosen language must be installed to wp-content/languages.
// For example, install de.mo to wp-content/languages and set WPLANG to 'de'
// to enable German language support.
define('WPLANG', 'fr_FR');
// uncomment this to enable wp-content/sunrise.php support
//define( 'SUNRISE', 'on' );
define( "WP_USE_MULTIPLE_DB", false );
/* That's all, stop editing! Happy blogging. */
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>
<?php
//What blogs where last updated, lets grab a bunch at first.
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='toileblogs.com' AND public = 1 AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 10 ");
$tables = array();
foreach ($blogs as $blog) {
// we need _posts and _options tables for this to work
$blogOptionsTable = "wp_".$blog."_options";
$blogPostsTable = "wp_".$blog."_posts";
$blogCatTable = "wp_".$blog."_post2cat";
//add to array for later use
$table = array ($blog, $blogPostsTable, $blogOptionsTable, $blogCatTable );
$tables[] = $table; //push into tables
}
//now lets pull out 10 recent posts from each blog
$postresults = array();
foreach ($tables as $t) {
$postitems = $wpdb->get_results("SELECT ID,post_title,guid,post_content,comment_count,post_date_gmt FROM $t[1] WHERE post_status = 'publish' AND guid != '' ORDER BY id DESC LIMIT 0,10");
//push into array, had $postresults[] = $postitems;, but didn't work?
if ($postitems) {
foreach ($postitems as $postitem) {
$col = array($postitem->ID,$postitem->post_title,$postitem->guid,$postitem->post_content,$postitem->comment_count,$postitem->post_date_gmt,$t[0]);
$postresults[] = $col;
}
}
}
function cutpost($text) { // Fakes an excerpt if needed
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 30;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
return $text;
}
function cmp($a,$b) {
$at = strtotime($a[5]);
$bt = strtotime($b[5]);
if($at == $bt)
return(0);
if($at < $bt)
return(1);
else
return(-1);
}
usort($postresults, 'cmp');
$postresults = array_slice($postresults, 0,10); //limit number of results
foreach ($postresults as $postresult) {
$siteurl = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='siteurl'");
$blogname = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='blogname'");
//todo - this is an array, need to sort and pull out
//$catitems = $wpdb->get_col("SELECT category_id FROM wp_".$postresult[6]."_post2cat WHERE $postitems->ID ORDER BY category_id");
?>
<?php
$postresult[1] = "$postresult[1]";
$postresult[1] = strtolower($postresult[1]);
$postresult[1] = ucfirst($postresult[1]);
?>
<a href="<?php echo $postresult[2]; ?>" rel="bookmark" title='Blog F1 : "<?php echo $postresult[1]; ?>"' target="_blank"><?php echo utf8_decode ($postresult[1]); ?></a> <br>
<?php } ?>
Je ne sais pas si beaucoup utilise wordpressMU. J'ai posé la question sur le forum officiel en français, et aucune réponse pour l'instant.