Seitentemplates mehrfach verwenden - Using a page template more than once

Ich werde immer wieder gefragt, ob es möglich ist ein Seitentemplate (z.B. 3-Column-Page) mehrfach zu verwenden. Die schnelle Antwort ist: Ja. In diesem Tutorial zeige ich Euch, wie das mit wenigen Schritten geht.

The english version of this tutorial can be found further down the page.

Die Datei kopieren

Zunächst muss man die relevante Datei kopieren. Im Beispiel verwende ich “3-column-page.php”. Ich öffne die Datei und speichere sie unter anderem Namen ab. Nennen wir sie doch ganz kreativ “3-column-page-2.php”.

Damit WordPress das Template auch erkennt…

…müssen wir nun nur die ersten 5 Zeilen des soeben kopierten Templates bearbeiten. Dort steht folgender Code:

< ?php
/*
Template Name: 3-Column-Page
*/
? >

Dieser Code bewirkt, dass WordPress diese Datei als Seitentemplate erkennt und später beim Schreiben der Seite in der Auswahl anbietet.

Wir ändern den Code jetzt einfach wie folgt:

< ?php
/*
Template Name: 3-Column-Page 2
*/
? >

Jajaja…wieder sehr kreativ, ich weiß. Aber es erfüllt seinen Zweck. Man könnte dem Template statt der angehängten “2″ natürlich auch einen beliebigen Namen verpassen. Ihr müsst damit später zurecht kommen.

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

Geht genauso. Beachtet bitte, dass ich ein Leerzeichen zwischen den PHP Tags gelassen habe (”<" und "?php"). Das muss natürlich entfernt werden. Ich muss das hier machen, da der Code sonst nicht dargestellt wird.

Inhalte anpassen

Das Template ist nun vorbvereitet. Jetzt müsst Ihr nur noch die Inhalte anpassen. Schließlich sollen ja nicht immer die gleichen Inhalte angezeigt werden. Dazu müsst Ihr die IDs der Kategorien anpassen, die das Template anzeigen soll. Im folgenden Beispiel wird in der ersten Spalte (von drei) die Kategorie mit der ID 5 angezeigt. Oben ein Artikelauszug mit Bild, Überschrift und Text. Unten noch mal 3 einzelne Überschriften der folgenden Beitröge aus dieser Kategorie.

Define the IDs

Seite veröffentlichen

Das Ganze dann speichern und dann in der WorpdPress Administration unter “Seite schreiben” als Template eben genau dieses Template auswählen. In WordPress 2.5 findet Ihr diese Auswahl unterhalb des Textfeldes. In früheren Versionen war das Dropdown Menü rechts neben dem Textfenster.


Sometimes I get asked if it´s possible to use the additional page templates more than once. The answer is: Yes. This tutorial shows you how.

Copy the file

Start by copying the relevant file. In this example we use “3-column-page.php”. Open the file and save as “3-column-page-2.php” (not very creative, I know).

To make WordPress recognize the template…

…we need to edit the first 5 lines of the file we just saved before. Open the file and you´ll see the following code:

< ?php
/*
Template Name: 3-Column-Page
*/
? >

This code let WordPress “know” that this is a specific page template called “3-Column-Page”. WordPress will provide the template in the pages write panel for selection.

Now we change the code as follows:

< ?php
/*
Template Name: 3-Column-Page 2
*/
? >

Yes, I know again not very creative. But it works. You don´t need to add the “2″ but you can name the template whatever you like. You might call it “Susan”…it´s up to you.

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

That also works. Please be aware of the fact that I had to add a space between the PHP tags (”<" and "?php") which you need to remove. Otherwise that will not work.

Edit the content

The template is prepared now. Now you just have to edit the content if you don´t like to display the same in every copy of your template (which I assume you don´t want). You have to edit the category IDs to match the categories you want to display. This example will display category 5 in column 1 (of 3). On top it shows an excerpt of the post with an image and a headline. Below the three next posts from this category are teasered as headlines only.

Define the IDs

Publish the page

Save it and go to your WordPress admin write page panel. Now you can select which template should be used for the page. In WordPress 2.5 the dropdown menu is below the textarea, in previous versions the dropdown is on the right side.




About this entry