WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

it:Pagine

In WordPress, potete creare articoli (posts) o pagine (pages). Quando state creando dei contenuti nel blog, state scrivendo un articolo. Gli articoli appaiono automaticamente in ordine cronologicamente inverso nella home page del vostro blog. Le pagine servono a contenuti come «A proposito di…», «Contatti», ecc. Le pagine vivono al di fuori della normale cronologia del blog, e sono spesso utilizzate per presentare informazioni estemporanee su voi stessi o sul vostro sito – informazioni che sono sempre valide. Potete utilizzare le pagine per organizzare e gestire qualsiasi contenuto.

Oltre alla classiche pagine fondamentali «A proposito di...» e «Contatti», altri esempi di pagine comuni includono copyright, notifiche, informazioni legali, permessi di riutilizzo, informazioni aziendali, e istruzioni di accessibilità.

In generale, le pagine sono molto simili agli articoli, nel senso che entrambi hanno un titolo e un contenuto e possono utilizzare i file template del vostro tema WordPress per conservare un aspetto consistente su tutto il vostro sito. Le pagine, tuttavia, possiedono alcune situazioni chiave che le rendono abbastanza diverse dagli articoli.

Cosa sono le pagine:

  • Le pagine sono per del contenuto che è meno dipendente al tempo rispetto ai post/articoli.
  • Le pagine possono essere organizzate in pagine e sotto-pagine.
  • Le pagine possono utilizzare diversi template di pagina che possono includere file di template, tag dei template e altro codice PHP.
  • Le pagine possono avere una più complessa gamma di aggiustamenti visivi prontamente disponibili, al posto di utilizzare temi sofisticati con ampie possibilità di personalizzazione.
  • In sostanza, le pagine sono per i contenuti non-blog. È possibile rimuovere tutti, o la maggior parte degli articoli da una installazione di WordPress, e, quindi, creare un sito web standard (non-blog).

Cosa NON sono le pagine:

  • Le pagine non sono articoli, e neppure sono tratte da grandi opere di narrativa. Esse non circolano attraverso la pagina principale del vostro blog. Sono disponibili i plugin WordPress per modificare il predefinito se necessario.
  • Le pagine non possono essere associate alle categorie e no si può assegnare ad esse i tag. La struttura organizzativa per le pagine dipende solo dalla loro interrelazione gerarchica, e non dai tag o dalle categorie.
  • Le pagine non sono file. Sono memorizzate nel tuo database proprio come succede agli articoli.
  • Anche se potrete inserire tag dei template e codice PHP all’interno di un template di pagina, non potrete mettere tutto ciò direttamente in un contenuto di pagina o articolo senza l’utilizzo di un plugin WordPress come Exec-PHP che sovrascrive il codice che filtra il processo.
  • Le pagine non sono incluse nel feed del tuo sito.
  • Pagine e articoli possono attirare l’attenzione in modi diversi sia da esseri umani che dai motori di ricerca.
  • Una pagina (o un articolo specifico), se lo si desidera, può essere impostata come prima pagina statica e con una pagina separata fissata per gli ultimi articoli del blog, in genere chiamata «Blog».

Creare le pagine

Pagine > Aggiungi nuova
Per creare una nuova pagina, eseguite il login nella vostra installazione di WordPress con sufficienti privilegi da amministratore per la creazione di nuovi articoli. Selezionate l’opzione Pagine > Aggiungi nuova per iniziare a comporre una nuova Pagina.

Organizza le tue pagine

Come esistono sottocategorie all'interno di una categoria, posso esserci «sottopagine» all'interno delle tue pagine in WordPress, creando quindi una gerarchia di pagine.

Per esempio, un sito WordPress per un’agenzia di viaggio potrebbe avere una pagina per ogni continente e nazione in cui l’agenzia organizza viaggi. All’interno della pagina denominata «Africa» potremmo avere delle sottopagine per Lesotho, Cameroon, Togo, e Swaziland. Un’altra pagina potrebbe essere «Sud America” con le sottopagine relative al Brasile, Argentina e Cile. Il sito sarebbe quindi così:

  • Africa
    • Cameroon
    • Lesotho
    • Swaziland
    • Togo
  • Sud America
    • Argentina
    • Brazil
    • Cile

Per creare sottopagine:

  1. Vai su Administration > Pages > Add New.
  2. Nel menu a destra, clicca nel menu a tendina «Pagina genitore». Il menu a tendina contiene una lista di pagine che sono già state create sul tuo sito.
  3. Seleziona la pagina genitore appropriata dal menu a tendina per rendere la pagina attuale una sua pagina child.
  4. Aggiungi del testo/contenuto nella sottopagina.
  5. Clicca su «Pubblica» quando è tutto pronto per la pubblicazione.

Quando le tue pagine sono ordinate, la pagina child viene inserita come sotto pagina della pagina genitore. Anche i Permalink delle tue pagine riflettono questa struttura delle pagine.

Nell’esempio di qui sotto, il Permalink per la pagina Cameroon sarà:

http://example.com/africa/cameroon/

Modificare URL delle pagine

Per cambiare URL o «slug» di una pagina, utilizzare l’opzione Modifica sotto il titolo della pagina sulla schermata di modifica.

Creare una lista di pagine

WordPress può «automaticamente» generare una lista di pagine sul tuo sito all’interno di una barra laterale o a piè di pagina, per esempio, usando tag dei template chiamato wp_list_pages(). Vedi anche la pagina dei wp_list_pages per avere più informazioni su come personalizzare il modo in cui WordPress mostra la lista delle pagine sul tuo sito.

Puoi anche collegare le tue pagine manualmente con un link HTML. Per esempio, se vuoi che la tua pagina copyright sia presente sul tuo footer a piè di pagina, puoi metterlo attraverso un link HTML come vedi sotto:

<a title=“Informazioni Copyright" href="http://example/com/copyright/">Copyright 1996-2012</a>

Ci sono anche dei plugin che ti aiutano a mostrare la lista delle pagina negli articoli o in altre aree del tuo tema WordPress.

Template/modelli di pagina

Singole pagine possono essere impostate per utilizzare uno specifico e personalizzato Page Template (un file PHP di template/modello di tema WordPress, ad es. snarfer.php) che potete creare all’interno del vostro tema. Vedi come creare un tuo template di tema personalizzato più giù, su come creare un file di modello personalizzato per una pagina. Questo nuovo template/modello di pagina sovrascriverà quello del template di pagina predefinito page.php incluso nel tuo tema.

WordPress può essere configurato per utilizzare vari template per diverse pagine. Per selezionare un template differente:

  1. Dal menu di destra, seleziona la voce dalla lista a discesa Modello.
  2. Scegli il file template di tema WordPress che deve essere utilizzato quando verrà visualizzata questa particolare pagina.

Cosa devi sapere sui template/modelli di pagina:

  1. In order to access the Page Template selector, there must be at least one custom Page Template available in the active theme (see Creating your own Page Templates below to learn how to create one). If a custom page exists, but you still are not able to see Page Template selector, re-activate your current theme.
  2. For a good understanding of how WordPress automatically uses specific Page template files in a Theme, see Template Hierarchy.
  3. If you change WordPress Themes, this Page Template file will no longer be available. The Page's layout and design will revert to the default look for the current WordPress Theme.

Default Theme Page Templates

The default TwentyEleven WordPress Theme contains three Page Templates for your use:

  • page.php - Default Page Template: displays Page content
  • archives.php - ignores Page content and instead displays a list of Archives by Month and Archives by Subject (by Category)
  • links.php - ignores Page content and instead displays your links using wp_list_bookmarks()

What Template is Used to Display a Particular Page?

WordPress looks for several Page template files in your active WordPress Theme based upon the Template Hierarchy. The first one it finds will be used to display any given Page. WordPress will look for files in the following order:

  1. The Page's selected "Page Template"
  2. page.php
  3. index.php

The WordPress Template Hierarchy also recognizes specific Pages or Posts automatically without the need to assign them to a specific Page template file. If the Page with ID or slug in the template file name is automatically generated by the user, the appropriate Page template file is used.

  • page-{id}.php
  • page-{slug}.php

If the Page ID number is 42, the page-42.php template file is automatically used. If the Page slug is "About," the page-about.php template file is used.

Creare un template di pagina personalizzato

I file che definiscono ognuno dei Modelli di Pagina si trovano nella vostra cartella Temi sotto /wp-content. Per creare una nuovo Modello Personalizzato di Pagina per una Pagina dovrete creare un file utilizzato un editor di Puro Testo (ad es. Notepad o TextWrangler). Chiamate il vostro primo Modello di Pagina snarfer.php.

In cima al file snarfer.php, inserite ciò che segue:

<?php
/*
Template Name: Snarfer
*/
?>

Il codice qui sopra è richiesto e definisce il file snarfer.php come il Modello "Snarfer". "Snarfer" può essere sostituito con qualsiasi testo per modificare il nome del Modello di Pagina. Il Nome del Modello apparirà nel WordPress Theme Editor per la modifica. Per ulteriori informazioni sulle convenzioni di nomina del Tema vedetevi nome file riservati per i Temi per i nomi di file che non dovreste utilizzare.

Quello che segue le prime cinque linee di codice dipende da voi. Il codice che scrivete controllerà appariranno le Pagine che utilizzano il Modello di Pagina Snarfer. See Template Tags for a description of the various WordPress Template functions you can use for this purpose. You may find it more convenient to copy the dynamic content generating code from another Template file (perhaps page.php or index.php) to snarfer.php. This will save time and allow you to only alter the HTML and PHP code instead of creating it all from scratch.

Once you have created and saved the file, upload it to your theme's folder inside wp-content/themes using FTP or whatever file management application your host provides.

Examples of Pages and Templates

The following is a list of instructional examples of custom Page Template files. Please note that your WordPress Theme's template file structure and architecture may be different.

Archives with Content

Example of a Page Template that shows the Page's content at the top, and then displays a list of archive months and categories below it.

Save this to arc-cont.php:

<?php
/*
Template Name: Archives with Content
*/
?>
<?php get_header(); ?>
<div id="content" class="widecolumn">
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
 <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
 <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
 </div>
 </div>
 <?php endwhile; endif; ?>
 <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
<div id="main">
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
<h2>Archives by Month:</h2>
 <ul>
  <?php wp_get_archives('type=monthly'); ?>
 </ul>
<h2>Archives by Subject:</h2>
 <ul>
   <?php wp_list_categories(); ?>
 </ul>
</div>
<?php get_footer(); ?>

A Page of Posts

The following custom Page Template file displays the content of the page followed by the posts from two specific categories (specified by their category slugs). It is designed to work within a child Theme of the Twenty Eleven theme. If you are using another theme, you need to replicate the HTML structure of your own theme within the template.

Save this to pageofposts.php and then assign the Page of Posts Template to your new Page:

<?php
/*
Template Name: Page Of Posts
*/

/* if you are not using this in a child of Twenty Eleven, 
*  you need to replicate the html structure of your own theme.
*/

get_header(); 
get_sidebar();
?>

<div id="primary">
  <div id="content" role="main">

  <?php
  /* the_post will retrieve the content of the new page you 
  *  create to list the posts, e.g. as an intro to describe 
  *  which posts are shown.
  */
  the_post(); 
  
  // Display content of page
  get_template_part( 'content', get_post_format() ); 
  wp_reset_postdata();

  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  $args = array(
	// Change these category SLUGS to suit your use.
	'category_name' => 'antiquarianism, championship', 
	'paged' => $paged
  );

  $list_of_posts = new WP_Query( $args ); 

  twentyeleven_content_nav( 'nav-above' );
  while ( $list_of_posts->have_posts() ): $list_of_posts->the_post();

    // Display content of posts
    get_template_part( 'content', get_post_format() );

  endwhile; 
  twentyeleven_content_nav( 'nav-below' ); 
  ?>

  </div><!-- /#content -->
</div><!-- /#primary -->
<?php get_footer();

Example Using Custom Fields

This example features a Page Template that displays posts from a specific category depending on a Custom Field assigned to a Page. The value of the Custom Field "category" is retrieved and used as the category to retrieve the posts in that category. If the category of posts you want to display is called "Events" then assign the Custom Field "category" with a value of "Events" to the Page. Note that this will adhere to pagination rules meaning that four (4) posts will display per page with links to older/newer posts provided.

Save this to pageofposts.php and then assign the Page of Posts Template when creating the action Page:

<?php
/*
Template Name: Page Of Posts with Custom Fields
*/

get_header(); ?>
<div id="content" class="narrowcolumn">
<?php
if (is_page() ) {
$category = get_post_meta($posts[0]->ID, 'category', true);
}
if ($category) {
 $cat = get_cat_ID($category);
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $post_per_page = 4; // -1 shows all posts
 $do_not_show_stickies = 1; // 0 to show stickies
 $args=array(
  'category__in' => array($cat),
  'orderby' => 'date',
  'order' => 'DESC',
  'paged' => $paged,
  'posts_per_page' => $post_per_page,
  'ignore_sticky_posts' => $do_not_show_stickies
 );
 $temp = $wp_query; // assign orginal query to temp variable for later use  
 $wp_query = null;
 $wp_query = new WP_Query($args); 
 if( have_posts() ) : 
		while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
	  <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
     <?php the_content('Read the rest of this entry »'); ?>
    </div>
    <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
   </div>
  <?php endwhile; ?>
  <div class="navigation">
   <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
   <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
  </div>
 <?php else : ?>
		<h2 class="center">Not Found</h2>
		<p class="center">Sorry, but you are looking for something that isn't here.</p>
		<?php get_search_form(); ?>

	<?php endif; 
	
	$wp_query = $temp; //reset back to original query
	
} // if ($category)
?>
	</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Example Using Custom Post Types

Custom Post Types allow WordPress sites to display many different types of content. This example displaying the posts on a Page belonging to a custom post type. In this case, the custom post type is book. The custom Page Template below can work in any Theme or as a Child Theme template file.

<?php
/**
 * Template Name: Page of Books
 *
 * Selectable from a dropdown menu on the edit page screen.
 */
?>

<?php get_header(); ?>
		<div id="container">
			<div id="content">
<?php 
$type = 'book';
$args=array(
 'post_type' => $type,
 'post_status' => 'publish',
 'paged' => $paged,
 'posts_per_page' => 2,
 'ignore_sticky_posts'=> 1
);
$temp = $wp_query; // assign ordinal query to temp variable for later use  
$wp_query = null;
$wp_query = new WP_Query($args); 
?>
<?php get_template_part( 'loop', 'index' );?>
	</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

La natura dinamica delle pagine WordPress

A web page can be static or dynamic. Static pages, such as a regular HTML page that you might create with Dreamweaver, are those which have been created once and do not have to be regenerated every time a person visits the page. In contrast, dynamic pages, such as those you create with WordPress, do need to be regenerated every time they are viewed; code for what to generate on the page has been specified by the author, but not the actual page itself. These use extensive PHP code which is evaluated each time the page is visited, and the content is thus generated upon each new visit.

Almost everything in WordPress is generated dynamically, including Pages. Everything published in WordPress (Posts, Pages, Comments, Blogrolls, Categories, etc...) is stored in the MySQL database. When the site is accessed, the database information is used by your WordPress Templates from your current Theme to generate the web page being requested.

An example of a static page might be an HTML document (without any PHP code). The problem with purely static pages is that they are difficult to maintain. Changes you make to your WordPress settings, Themes and Templates will not be propagated to pages coded only in HTML. The Page feature of WordPress was developed to alleviate this problem. By using Pages, you no longer have to update your static pages every time you change the style of your site. If written properly, your dynamic Pages will update along with the rest of your blog.

Despite the dynamic nature of Pages, many people refer to them as being static. They are actually called "pseudo-static" web pages. In other words, a Page contains static information but is generated dynamically. Thus, either "static," "dynamic," or "pseudo-static" may be validly used to describe the nature of the WordPress Page feature.