Home › Forum › Plugin e temi di WP › Includere l’ultimo topic di wordpress in una pagina esterna
-
AutorePost
-
-
27 Maggio 2008 alle 21:16 #6780davidexPartecipante
Salve a tutti,
avrei bisogno di una mode che mi permette di includere l’ultimo topic di wordpress (di una determinata categoria) in una pagina esterna al blog. Premetto che blog e pagina esterna si trovano nello stesso server.
Quindi se wordpress è installato su http://www.sito.ext/blog e la pagina esterna è http://www.sito.ext/index.php come posso includere in quest’ultima l’ultimo topic di una determinata categoria??
grazie mille a tutti
-
27 Maggio 2008 alle 22:23 #54027wollyAmministratore del forum
probabilmente il metodo più veloce è quello di utilizzare i feed rss della categoria utilizzando uno script che legga i feed.
-
27 Maggio 2008 alle 22:32 #54029davidexPartecipante
non c’è un tutorial che spiega il tutto?? io ho visto un pò in giro.. ma non ho trovato nulla! può essere che nessuno abbia realizzato una mod a riguardo? mi sembra strano.
grazie
-
27 Maggio 2008 alle 22:36 #54030wollyAmministratore del forum
cerca su html.it uno script che legga i feed rss.
Non puoi fare plugin esterni a wordpress, quello che vuoi fare tu non centra con wordpress ma eventualmente con php o html o javascript.
-
27 Maggio 2008 alle 23:12 #54031SteveAglAmministratore del forum
Non puoi fare plugin esterni a wordpress, quello che vuoi fare tu non centra con wordpress ma eventualmente con php o html o javascript.
oddio, non è proprio esatto
Una delle caratteristiche più eccelse di WP è che se tu da un file php esterno a WP fai un include del file
wp-blog-header.php
ecco che all’interno di quel file esterno hai a disposizione tutto l’arsenale di variabili, tag e funzioni di WP, plugin compresi.Per cui a quel punto puoi usare la classe
$wpdb
per interagire con il database oppure usare unget_posts
:<?php
include('blog/wp-blog-header.php');
global $post; // questa non so se serve...
$myposts = get_posts('numberposts=1&category=1');
foreach($myposts as $post) :
the_title();
endforeach; ?>
-
28 Maggio 2008 alle 12:10 #54040davidexPartecipante
Ottimo.. questo script funzia. seppur in modo molto limitato. Posta solo il titolo non linkato.
E’ possibile implementarlo per far si che prelevi il titolo linkato e il contenuto del post fin quando non trova l’interruzione del link “continua a leggere”?.
Grazie
-
28 Maggio 2008 alle 13:19 #54041SteveAglAmministratore del forum
Il link inizialmente l’avevo messo nell’esempio, ma il forum continuava a mangiarselo (SteveAgl, possiamo fare qualcosa?).
Ho lasciato solo
the_title();
con la speranza che tu intuissi che oltre a quello potevi usare altri tag di template (non hai fatto delle prove no?) sull’esempio del template di default.Per cui: all’interno del ciclo
foreach($myposts as $post):
puoi usare tutti i tag relativi agli articoli usati nel Loop. -
29 Maggio 2008 alle 12:47 #54085davidexPartecipante
Grazie mille per i tag di template non ci avevo pensato.
In effetti sto facendo delle prove.. sono riuscito a linkare il title
ho aggiunto il tag the_content() con la speranza che mi stampasse anche il contenuto del topic.. ma nulla…
<?php
include(‘blog/wp-blog-header.php’);
global $post; // questa non so se serve…
$myposts = get_posts(‘numberposts=1&category=1’);
foreach($myposts as $post) : ?>
<?php the_content() ?>
<?php endforeach; ?>
cosa sbaglio??
grazie
-
29 Maggio 2008 alle 14:15 #54087wollyAmministratore del forum
Perdonami se insisto ma fai MOLTO più in fretta ad utilizzare uno script php che legge i feed e legarlo al feed della categoria che ti interessa.
Ciao
-
29 Maggio 2008 alle 17:53 #54103ArturoPartecipante
Il codice da me consigliato, che ho testato funziona ed e’ il seguente:
<?php
require(‘blog/wp-blog-header.php’);
?>
<?php
// stampa il numero di post di quella determinata categoria basandosi sull’ID
query_posts(‘showposts=1&cat=289’);
global $more;
// imposta $more a 0 per ottenere solo la prima parte del post se more e’ presente
$more = 1;
// il Loop
while (have_posts()) : the_post(); ?>
< a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permalink a <?php the_title(); ?>”><?php the_title(); ?></ a>
<?php the_content(‘Continua a leggere…’); ?>
<?php endwhile;
?>
that’s all!
-
30 Maggio 2008 alle 0:26 #54109davidexPartecipante
Grazie mille.. infatti funziona alla grande!! era proprio questo che cercavo ) grazie ancora.
-
20 Giugno 2008 alle 12:33 #54977alessandro85Partecipante
a me non funge l’ultimo script.. mi dice:
Warning: main(./blog/wordpress/wp-blog-header.php) [function.main]: failed to open stream: No such file or directory in /web/htdocs/www.intotheoz.com/home/test/index.php on line 29
Fatal error: main() [function.require]: Failed opening required ‘./blog/wordpress/wp-blog-header.php’ (include_path=’.:/php/lib/php/’) in /web/htdocs/www.intotheoz.com/home/test/index.php on line 29
-
23 Giugno 2008 alle 8:31 #55098baguPartecipante
A me il codice postato da Arturo funziona (quasi) perfettamente.
Unico problema la codifica carattere IL blog è settato utf-8, mentre la pagina, settata sia iso che utf-8 mi da parecchi caratteri strani.
(vedi qui).
Risolverei con l’uso nei settaggi del blog di UTF8_general_ci, ma mi incasina tutti i post vecchi…
qualcuno ha risolto?
-
26 Ottobre 2009 alle 21:54 #69063bennyPartecipante
Domanda: il codice di arturo mi funziona…però…io ho una homepage che dovrebbe contenere gli ultimi post di due blog…ma lo scritp, mi pesca solo il wp-blog-header.php principale (l’altro wp-blog-header.php) è in una sotto cartlella. help
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.