Home › Forum › Problemi Vari con WP › is_page e template personalizzato
-
AutorePost
-
-
29 Marzo 2016 alle 6:39 #30739MarcoRM69Partecipante
Ciao a tutti.
Ho un problema che non riesco a comprendere.
Partendo dal page.php ho creato un template personalizzato. Ho poi creato una nuova pagina applicando questo nuovo template.
La cosa funziona, l’unico problema è che non vorrei la sidebar su questa pagina. Spulciando il tema non sono riuscito ancora a capire da dove viene richiamata la funzione che visualizza la sidebar, ho trovato però la funzione.
E’ una serie di controlli sui tag condizionali per mostrare o meno la sidebar in base alla pagina, ho pensato quindi di aggiungere anche il mio template.
Il problema è che non riesco a capire il perché il mio template viene visto come un “post” e non come una “page”. Il controllo cosଠmi risulta complesso. Non funziona ne inserendo is_page(‘nomepagina’) né con is_template_page(‘nometemplate’) né usando i nomi dei files.
Insomma, non capisco perché una pagina viene vista come un post.
Aggiungendo le seguenti funzioni al codice del template
1. echo get_post_type();
2. echo get_page_template();
il risultato è
1. post
2. page.php
Anche il secondo risultato mi lascia perplesso, perché mi da page.php invece del page-miotemplate.php?
Ho letto qualcosa riguardo il suffisso, ma anche cambiando il nome del template in custom-miotemplate.php il risultato non cambia.
Grazie per l’eventuale aiuto
(nel frattempo continuo a spulciare il codice per cercare dove viene effettuata la chiamata alla funzione che mostra la sidebar)
Marco.
-
29 Marzo 2016 alle 9:33 #120215SteveAglAmministratore del forum
QUandof ornirai le info utili per aiutarti magari, visto che non hai letto quello che dovevi … indovina cosa?
-
29 Marzo 2016 alle 16:00 #120220MarcoRM69Partecipante
Perdonami, temo di non capire.
Ho letto (e l’ho rifatto anche ora) gli avvisi e gli elenchi di cosa fare e non fare.
Non credo di aver “violato” questo regolamento.
Se l’aver letto era riferito alle guide di wordpress, ho letto anche quelle, ma i miei dubbi sono rimasti.
Ho semplicemente chiesto, visto che la cosa mi sembra strana, perché una PAGINA (creata come tale) viene “vista” come post. Immaginavo, da neofita di WP, che una pagina fosse sempre una pagina ed un post sempre un post.
Se servono altre informazioni ditemi quali, non conoscendo, ripeto, WP, mi risulta difficile sapere quali altre informazioni possano essere necessarie.
Grazie,
Marco
-
29 Marzo 2016 alle 17:26 #120221TittiModeratore
Nessun tema è uguale. Per questo chiediamo i link diretti al tema, alla pagina, al file, al sito e verso qualsiasi altra cosa interessata dalla domanda. Tu invece fai domande astratte su qualcosa che non vediamo.
Inoltre non dici se stai lavorando su un tema child, e non si capisce a cosa ti riferisci con “viene vista come un post”: anche la pagina, come gli attachment, le revisioni, i post e gli oggetti del menu è un “post type” – e se hai “semplicemente” chiesto questo e il resto non conta, allora questa è la risposta.
-
29 Marzo 2016 alle 17:42 #120222MarcoRM69Partecipante
Ok, come detto sono nuovo di WP, quindi perdonate le mancanze.
Intanto grazie per il chiarimento sul post_type, pensavo fossero oggetti diversi, cosଠcome non pensavo fosse importante conoscere il tema usato sul risultato di una funzione di WP.
Nel frattempo, smadonnando a destra e manca ho capito il mio errore. Inserivo le due chiamate che mi servivano:
get_post_type();
get_page_template();
Prima della wp_reset_query(), come nell’esempio ‘semplificato’ qui sotto.
Spostandole dopo le funzioni mi restituiscono quanto atteso.
$wp_query = new WP_Query( $args );
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
get_template_part('templates/content', 'blogfullwidth'); ?>
<?php endwhile;
echo get_post_type();
echo get_page_template();
wp_reset_query();
In ogni caso grazie per l'aiuto e scusate il disturbo.
Marco.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.