Codex

pt-br:Criando Páginas

Contents

No WordPress, você pode criar postagens e páginas. Postagens aparecem automaticamente em ordem cronológica inversa na página inicial do seu blog. Páginas, por outro lado, são para conteúdo estático.

Páginas ficam fora da cronologia normal do blog e muitas vezes são utilizadas para apresentar informações sobre você ou seu site, o que é de alguma forma atemporal - informação que são sempre aplicáveis. Você pode usar páginas para organizar e gerenciar qualquer quantidade de conteúdo.

Outros exemplos comuns de páginas incluem direitos de autor, Informação Jurídica, permissões de re-impressão, Informação de Companhia e Declaração de acessibilidade. (Por exemplo, é uma boa ideia ter sempre uma página com informações de contato.

Em geral, as páginas são muito semelhantes a postagens porque que ambas têm títulos e conteúdos e podem usar Modelos de Apresentação para manter uma aparência consistente em todo o site. Páginas, no entanto, têm várias distinções que as tornam bem diferente de Postagens.

Páginas em resumo

O que são

  • Páginas são para conteúdos fixos, como Dados sobre Você, Como entrar em contato etc.
  • As páginas podem ter subpáginas.
  • As páginas podem ser quebradas em páginas para facilitar a leitura.
  • As páginas podem usar diferentes modelos entre si e podem conter códigos do tipo PHP e Tags de Modelo.

Como não devem ser usadas:

  • Páginas não são Postagens! Elas não percorrer a página principal do seu blog.
  • Páginas não podem ser organizadas dentro de categorias e a elas não se pode atribuir Tags. A estrutura organizacional para páginas são apenas inter-relações hierárquicas e não através de Tags ou categorias.
  • Páginas não são arquivos e não geram arquivos! Elas são armazenadas no banco de dados, como os postagens são.
  • Embora você possa colocar Tags de Modelos e código PHP em um Modelo de Páginas, não é possível inserir diretamente código PHP e esperar que sejam executados sem um plugin como o Exec-PHP).

Criando Páginas

Para criar uma nova página, inicie a sessão no WordPress com privilégios suficientes para criar novos artigos. Vá em Painel > Páginas > Adicionar Nova.

O documento SubPainel Páginas-Adicionar Nova possui explicações detalhadas sobre cada item da tela de adicionar páginas.

Organizando Páginas

Exemplo de Organização de Páginas

África

-Angola
-Moçambique
-Zimbábue

Ásia

-China
-Coréia do Sul
-Japão

Europa

-Alemanha
-França

Assim como você pode ter Subcategorias dentro de categorias, você também pode ter SubPáginas dentro de suas páginas, criando uma hierarquia de páginas.

Suponha que você está criando um site WordPress sobre viagens e gostaria de criar uma página individual para cada continente e país em que viajou. Você poderia começar por criar uma página chamada "África" em que você poderia descrever informações gerais sobre a viagem à África. Então você teria que criar uma série de páginas que seriam SubPáginas relacionadas a "África" ou por exemplo, os países ou cidades que conheceu. Outra página individual é feita para "América do Sul" e que apresentam subpáginas de cada país que conheceu.


Para criar subpaginas, é só definir sua página pai enquanto estiver criando uma página normalmente. Veja o documento Adicionar Nova Página

Mostrando Páginas no Site

WordPress é capaz de gerar automaticamente uma lista de páginas do seu site. Há basicamente quatro maneiras de mostrar as páginas que criou em seu site:

Widget Páginas

Se o seu tema suporta widgets, adicione o item Páginas à sua área de widgets para mostrar todas as suas páginas. Você pode mostrar como lista suspensa, excluir páginas da exibição etc.

  1. Vá em Painel > Aparência > Widgets
  2. Adicione o item Páginas
Menus do tema

Se o seu tema suporta a funcionalidade de menu do WordPress, é possível inserir páginas em um menu que será mostrado pelo tema.

  1. Vá em Painel > Aparência > Menus
  2. Crie um menu
  3. Adicione as páginas ao menu criado, marcando-as na caixa de páginas à direita.
Usando links para a página (Não recomendado)

Se for um link apenas, para uma página sobre o seu tema por exemplo, poderá criar um link comum para a página como qualquer link, usando tag HTML comuns.

  1. Abra o arquivo do tema, por exemplo footer.php
  2. Insira o código: <a href="http://www.exemplo.com/meu-tema">Sobre este tema</a>

Nota:Você deve configurar Links Permanentes para ter um link legível em vez de um número como <a href="http://www.exemplo.com/?p=12">Sobre este tema</a>.

Tags de Modelos (Avançado)

Qualquer área do seu tema poderá mostrar uma lista de páginas do seu site, juntamente com opções várias de exibição.

  1. Abra um arquivo do tema como sidebar.php
  2. Adicione a tag de modelo wp_list_pages()
Artigo parcialmente traduzido ou que precisa de tradução
Este documento está parcialmente traduzido para Português do Brasil ou precisa ser traduzido.
Cadastre-se e comece a Contribuir. Insira links da lista de Artigos.

Modelos de Páginas

Individual Pages can be set to use a specific custom Page Template (a PHP template file, e.g., snarfer.php) you create within your Theme (see Creating your own Page Templates below on how to create a custom template). This new Page Template will then override the default page.php Page Template included with your Theme. See What Template is used to Display a Particular Page? below, to find out exactly which Template will be used, but read the following first, so you understand the answer :)

WordPress can be configured to use different Page Templates for different Pages. Toward the bottom of the Write > Page administration panel (or on the sidebar, depending on which version of WordPress you are using) is a drop-down labeled "Page Template." From there you can select which Template will be used when displaying this particular Page.

NOTE: 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, try to re-activate your current theme.

Default Theme Page Templates

The Default 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 will look for several template files in your active Theme. 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
Artigo ou Seção com explicações avançadas
A seguir, estão explicações ou instruções para administradores de redes ou programadores.
Adicione {{Avançado}} para usar esta caixa.

Creating Your Own Page Templates

The files defining each Page Template are found in your Themes directory. To create a new Custom Page Template for a Page you must create a file. Let's call our first Page Template for our Page snarfer.php. At the top of the snarfer.php file, put the following:

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

The above code defines this snarfer.php file as the "Snarfer" Template. Naturally, "Snarfer" may be replaced with most any text to change the name of the Page Template. This Template Name will appear in the Theme Editor as the link to edit this file.

The file may be named almost anything with a .php extension (see reserved Theme filenames for filenames you should not use; these are special file names WordPress reserves for specific purposes).

What follows the above five lines of code is up to you. The rest of the code you write will control how Pages that use the Snarfer Page Template will display. 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 some other Template (perhaps page.php or index.php) to snarfer.php and then add the above five lines of code to the beginning of the file. That way, you will only have to alter the HTML and PHP code, instead of creating it all from scratch. Examples are shown below. Once you have created the Page Template and placed it in your Theme's directory, it will be available as a choice when you create or edit a Page. (Note: when creating or editing a Page, the Page Template option does not appear unless there is at least one template defined in the above manner.)

Examples of Pages and Templates

The following is a list of instructional examples. Feel free to make additions.

Archives with Content

A Page Template that shows the Page's content at the top, and then displays a list of archive months and categories below it. This is designed to work with WordPress's Default theme (aka Kubrick), but will probably work with many other themes with a little modification.

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_cats(); ?>
  </ul>

</div>
<?php get_footer(); ?>

A Page of Posts

A Page Template that displays posts from a specific category depending on what Page is being displayed. This is designed to work with the WordPress Default theme (aka Kubrick), but may work with other themes with a little modification.

Save this to pageofposts.php:

<?php
/*
Template Name: PageOfPosts
*/

get_header(); ?>

	<div id="content" class="narrowcolumn">

<?php
// page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
if (is_page('21') ) {
$cat = array(12);
} elseif ( is_page('16') ) {
$cat = array(32);
} elseif ( is_page('28') ) {
$cat = array(17);
} else {
$cat = '';
}

$showposts = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
   'category__in' => $cat,
   'showposts' => $showposts,
   'caller_get_posts' => $do_not_show_stickies
   );
$my_query = new WP_Query($args); 

?>

	<?php if( $my_query->have_posts() ) : ?>

		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
			<?php
			//necessary to show the tags 
			global $wp_query;
			$wp_query->in_the_loop = true;
			?>
			<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; ?>

	<?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; ?>

	</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

WordPress as a CMS

You can use WordPress for basic content management. If you do, you'll probably create a large number of pages for your content.

Using a Page as the Front Page

A Page can easily be set to be your site's Front Page. Visit the Administration > Settings > Reading panel and under Front page displays, you can choose to set any (published) Page or Posts Page as the Front Page. The default setting shows your blog with the latest blog posts.

Including a Page

You might also want to include Pages in various places on your site. That way, you can have an easy way to edit elements of your website. There is a Plugin called Improved Include Page that makes doing this easy.

The Dynamic Nature of WordPress "Pages"

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 it. 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 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 on the fly, upon each new visit.

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

An example of a static page might be an HTML document (without any PHP code) you've written as an addition to your dynamically generated WordPress pages, perhaps an "About Me" page. 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, in part, to alleviate this problem. By using Pages, users no longer have to update their static pages every time they change the style of their site. Instead, if written properly, their dynamic Pages will update themselves along with the rest of your blog.

Despite the dynamic nature of Pages, many people refer to them as being static. In the context of web publishing, static and dynamic mean what has been described above. More generally, however, static can mean "characterized by a lack of change". It is easy to see how this definition influenced the word's use in describing types of web pages. It is also easy to see why people think of Pages as being static; Posts come and go, but Pages are here to stay since Pages are typically used to display information about your site which is constant (e.g., information about yourself, description of your site).

In other words, a Page contains static information but is generated dynamically. Thus, either "static" or "dynamic" may be validly used to describe the nature of the WordPress Page feature. However, in order to avoid confusion, and because Pages themselves are dynamic while it is only their contents which are in some way static, this document does not refer to Pages as being static.


Related content:

WordPress Brasil
Artigos sobre o WordPress em Português-Brasil.
Todas as comunidades lusófonas também são bem-vindas! Adicione {{Codex-pt}} em seus artigos.