- Home
- Categorie
- Coding e Sistemistica
- PHP
- Tabella contenente le ultime news
-
Tabella contenente le ultime news
Salve gente,
vorrei creare una tabella da mettere nella mia HomePage contenente gli ultimi messaggi postati su un Blog.
Un po' come succede per la Home di giorgiotave.it.Pensavo a qualcosa con gli RSS, avete idee?
-
$sql = 'SELECT post_title , post_date_gmt FROM
wp_posts
'
. ' LIMIT 0, 30 ';$sql = 'SELECT display_name FROM
wp_users
LIMIT 0, 30 ';Ecco i due codici php.
-
Che ne dite, può andare?
[PHP]<?php
// connessione
mysql_connect(host,user,password) ;
mysql_select_db(blog_thecyberplanet);// ottiene i post
$query = mysql_query('SELECT post_title,post_author, post_date_gmt FROMwp_posts
LIMIT 0, 30');
?><table border="1">
<tr><td><b>Post</b></td><td><b>Autore</b></td></tr>
<?php
while($row=mysql_fetch_array($query))
{
?>
<?php
// ottiene il nome dell'autore
$query = mysql_query('SELECT display_name FROMwp_users
WHERE ID='.$row['post_author'].' LIMIT 1');
$author=mysql_fetch_array();
?>
<tr><td><?php echo $row['post_title'] ?></td><td><?php echo $author['display_name'] ?></td></tr>
<?php
}
?></table>[/PHP]
-
[PHP]$sql = 'SELECT post_title, post_date_gmt, display_name'
. ' FROM wp_posts JOIN wp_users ON wp_posts.post_author = wp_users.ID'
. ' ORDER BY post_date_gmt DESC'
. ' LIMIT 0, 30';
[/PHP]Che dite, è meglio?