Home › Forum › Problemi Vari con WP › Problema con custom query e navigation links
-
AutorePost
-
-
13 Agosto 2010 alle 12:40 #14741cammelloAfganoPartecipante
Ciao a tutti,
ho un problema che non riesco a risolvere… si tratta del malfunzionamento dei nav links generati dai metodi next_posts_link e prev_posts_link.
Il malfunzionamento si verifica se inserisco una QUALSIASI query_posts custom:
global $query_string;
query_posts($query_string . “&posts_per_page=3”);
(in realtà posso metterci anche una query_string dove non viene usato il parametro posts_per_page, come ad esempio query_posts($query_string . “&post_status=future&order=ASC”); )
Questo codice l’ho messo in cima allo script, subito dopo il get_header();
Il problema si verifica quando nella pagina caricata (http://www.giovannigarzella.it/wordpress/category/eventi), dove la query funziona, clicco su “« Vecchi articoli” generato dal metodo get_next_posts_link e passo alla pagina successiva (http://www.giovannigarzella.it/wordpress/category/eventi/page/2) dove in pratica mi viene caricata la 404.php…
Avevo letto una cosa al riguardo sulla guida di wordpress alla pagina http://codex.wordpress.org/Using_Permalinks sotto “Paged Navigation Doesn’t Work: Sometimes navigation to second (and subsequent) pages of posts does not work as expected. Your page may generate a link…”
Ora però questo problema mi si verifica solo con la custom query, perché se la tolgo, tutti riprende a funzionare normalmente e la pagina 2 mi viene caricata perfettamente, con la corretta lista.
Sapete di che si tratta per caso? Avete riscontrato un problema simile?
-
13 Agosto 2010 alle 12:54 #76200wollyAmministratore del forum
-
13 Agosto 2010 alle 12:56 #76201wollyAmministratore del forum
Preserving the Original Query (Pagination etc.)
By default running query_posts will completely overwrite all existing query variables on the current page. Pagination, categories dates etc. will be lost and only the variables you pass into query_posts will be used.
If you want to preserve the original query you can merge the original query array into your parameter array:
global $wp_query;
query_posts(
array_merge(
array(‘cat’ => 1),
$wp_query->query
)
);
-
13 Agosto 2010 alle 13:23 #76204cammelloAfganoPartecipante
Grazie Wolly,
ho provato subito la tua soluzione ma sembra non funzionare.
Prima del get_header() (poi hop provato pure a metterlo dopo), ho scritto:
global $wp_query;
query_posts(array_merge(
array(‘post_status’ => ‘future’, ‘posts_per_page’ => 2),
$wp_query->query
)
);
Niente.
poi ho provato una query più semplice:
global $wp_query;
query_posts(array_merge(
array(‘posts_per_page’ => 1),
$wp_query->query
)
);
Ma continua a non andare, visto che i post in questo caso sono due e quindi a pagina 2 mi dovrebbe far vedere il secondo post, invece mi và alla 404.php
-
13 Agosto 2010 alle 13:32 #76206wollyAmministratore del forum
hai ricreato i permalink?
-
13 Agosto 2010 alle 13:40 #76208cammelloAfganoPartecipante
Wolly,
dici da pannello di controllo o da codice?
Io nel pannello di controllo ho questo settaggio: http://www.giovannigarzella.it/permalinks.jpg
-
13 Agosto 2010 alle 15:33 #76213cammelloAfganoPartecipante
Se per permalinks invece intendi quelli creati da next_posts_link() e prev_posts_link() si, li ho messi dopo la query e prima del loop.
Ciao
-
13 Agosto 2010 alle 18:31 #76219wollyAmministratore del forum
ricreare i permalinks significa entrare nella sezione permalink e ricrearli.
-
13 Agosto 2010 alle 18:54 #76220cammelloAfganoPartecipante
Ok Wolly,
però la struttura personalizzata /%postname%.html mi sembra quella più corretta.
Ho comunque salvato nuovamente i permalinks, ma il problema sussiste lo stesso.
Quello che vorrei capire é se qualcun altro ha avuto lo stesso problema, cioé se modificando una query con la struttura che hai scritto tu (query_posts array_merge) e inserendo i metodi prev_posts_link e next_posts_link, questi ultimi mostrano risultati corretti se passo alla pagina successiva (%postaname%.html/page2).
Capirei cosଠse effettivamente si tratta di un bug di wordpress, un metodo non usato che mi sfugge, un codice scritto male oppure l’intera struttura del sito che non và .
-
13 Agosto 2010 alle 19:03 #76221wollyAmministratore del forum
hai messo anche il rewind quesry come hanno messo nel primo esempio?
-
13 Agosto 2010 alle 19:35 #76222cammelloAfganoPartecipante
Si Wolly,
ho appena provato mettendo il rewind_posts(); dopo end_while; (fine del loop have_posts()) e poi ho aggiunto un wp_reset_query(); prima del get_footer().
Il problema é proprio la custom query, perché se lascio quella di default (con posts_per_page settata da pannello di controllo nella sezione Lettura -> Le pagine del blog visualizzano al massimo: 6 posts), i nav links vanno perfettamente!
Ad esempio:
http://www.giovannigarzella.it/wordpress/category/video-dal-mondo/page/2 esiste, non mi rimanda alla 404.php.
Se commento la custom query, anche http://www.giovannigarzella.it/wordpress/category/eventi/page/2 dà dei giusti risultati… L’ho appena fatto e và , solo che io ho bisogno di inserire una custom query con post_status => ‘future’ per visualizzare solo gli eventi che devono ancora venire e poterli cosଠordinarli per data (quella del post programmato, stabilita direttamente dal pannello di controllo al momento della creazione dell’articolo).
-
23 Agosto 2010 alle 9:00 #76463cammelloAfganoPartecipante
Ciao,
son tornato dalle ferie e speranzoso sono subito andato a leggere il topic che avevo creato, ma vedo che dopo il mio ultimo intervento non ci sono state risposte.
Devo pensare che il problema non sia di facile soluzione?
Desideravo solo sapere se sono stati effettivamente incontrati bugs con i navigation links relativi ad una custom query inserita ad inizio pagina o se solo io li ho riscontrati.
Ciao
Giovanni
-
28 Agosto 2010 alle 12:46 #76626cammelloAfganoPartecipante
Per chi avesse questo stesso problema posto qui il link con la soluzione:
http://wordpress.org/support/topic/custom-query-only-displays-4-posts-rest-is-404?replies=3
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.