Home › Forum › Problemi Vari con WP › Per pubblicare il contenuto completo solo dell’ultimo post
-
AutorePost
-
-
29 Aprile 2010 alle 7:25 #13738vagamentePartecipante
Salve. Vorrei che solo l’ultimo post venisse pubblicato per intero mentre tutti gli altri solo un estratto.
Ho pensato di utilizzare la funzione di WP get_lastpostmodified() e effettuare all’interno del loop una comparazione tra data del post in questione e risultato di get_lastopostmodified().
Mi da sempre sull’if come risultato “falso” mentre dovrebbe dare una volta vero (nessun messaggio di errore…).
Ho provato, per debug, a creare un output per ogni variabile. Ho creato anche una $test per vedere il risultato di una sottrazione tra $data e $ultimo ma calcola in maniera a me incomprensibile.
Il codice (snippato) è questo:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $ultimo= (date("Ymd", strtotime(get_lastpostmodified())));?>
[...]
" title="<?php the_title(); ?>"><h1><?php the_title() ?></h1>
[...]
<?php
$data=(the_date(Ymd));
$test=strcmp($ultimo, $data);
print "$data rispetto $ultimo poi $test";
if ($data == $ultimo) { print(Uguali); the_content(); } else { the_excerpt(); }?>
<?php endwhile; endif;?>
[...]
L'output lo trovate all'indirizzo http://iparalipomenidi.vagamente.net qua.
Dove sta l'inghippo?
Grazie
Massimiliano
-
29 Aprile 2010 alle 9:08 #73124vagamentePartecipante
Trovato!!!
Il problema stava nel fatto che utilizzavo la funzione di WP the_date() (pensata per visualizzare una data) invece della funzione get_the_date() che invece recupera semplicemente il valore.
Ora funziona.
Il codice corretto se qualcuno vuole riutilizzarlo quindi è questo:
Codice:
<?php $ultimo= (int) (date(“Ymd”, strtotime(get_lastpostmodified())));?>
” title=”<?php the_title(); ?>”><h1><?php the_title() ?></h1>
<?php $data= (int) date(get_the_time(Ymd));
if ($data == $ultimo) the_content();
else{
the_excerpt();?>
<p>” class=”continue”>Continua a leggere questa roba qua »</p>
<?php } ?>
Saluti
-
29 Aprile 2010 alle 9:31 #73125SteveAglAmministratore del forum
se il post da mostrae per intero è il primo sempre allora molto più semplice un contatore che se diverso da 1 mostra il riassunto se no il testo completo, più semplice, meno uso di funzioni etc etc
-
23 Gennaio 2012 alle 11:00 #92379neohiroPartecipante
Ciao a tutti, intervengo su questo argomento dopo quasi due anni, comprenderò se non avrò risposte.
Lo script di vagamente sembra essere ok, ma la soluzione suggerita da SteveAgl, mi sembre ottima, più lineare, ora, a questo punto, domando… quancuno ha già fatto lo script di cui si aprla? Io non sono in grado e ringrazierò infinitamente chi mi darà dritte, grazie
Max
-
23 Gennaio 2012 alle 11:28 #92382wollyAmministratore del forum
lo trovi nelle faq
-
23 Gennaio 2012 alle 16:39 #92388neohiroPartecipante
Ciao Wolly, grazie, ma non lo trovo mica, ne ho trovato uno per visualizzare un solo articolo in home, oppure tagliare tutti gli articoli, ma uno dove parli di avere l’ultimo articolo inserito completo e gli altri solo un abstract, non lo trovo…
continuerò a cercare, grazie
max
-
23 Gennaio 2012 alle 17:18 #92391wollyAmministratore del forum
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.