Ok, hier mal das Template für meine alte Startseite (johannes-ruthenberg.de). Bitte darüber hinwegsehen, dass ich an einigen Stellen eigene Methoden aufrufe, mir fehlt gerade die Zeit das umzuschreiben. Das Prinzip sollte aber klar werden.
Ganz grob: Ich habe ein Array mit den IDs der Kategorien, die auf der Startseite dargestellt werden sollen. Für diese wird jeweils der neueste Artikel als Teaser und die vier nächsten als verlinkte Überschrift dargestellt. Ganz oben steht noch ein Text, das ist der Text aus der statischen Seite, die als Startseite fungiert. Der Code ist von 2007, keine Garantie also dass das nicht mit neueren WP-Funktionen hier und da einfacher geht. Laufen tut es aber. Am besten bei Problemen direkt im Codex nach Lösungen suchen, z.B. zur Darstellung eines Kategorienamens. Alles mit "dor_"-Präfix sind meine eigenen Variablen oder eben Methoden.
<?php
/**
* Template Name: Startseite
*
* This page is the theme's start page.
*/
// build an array of category IDs
$dor_categories = array(1, 15, 41, 47, 9);
?>
<?php get_header(); ?>
<div id="contentarea">
<!-- begin content -->
<div id="content"><div class="inner">
<a name="jumpToPageContent" class="invisible"></a>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<p class="breadcrumb"> </p>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif"><strong>Den ganzen Beitrag lesen...</strong></p>'); ?>
</div>
<p class="postmetadata"><?php edit_post_link('Seite bearbeiten', '', ' <strong>|</strong>'); ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php
// keep the original query
$original_query = $wp_query;
// query posts of categories
for ($dor_i = 0; $dor_i < count($dor_categories); $dor_i++) {
// get the category ID
$dor_cat_id = $dor_categories[$dor_i];
// query posts of the category
$wp_query = new WP_Query('cat=' . $dor_cat_id . '&showposts=6');
// output the result if anything was found
if ($wp_query->have_posts()) {
// output the headline
$dor_cat_name = dor_the_category_name($dor_cat_id);
?>
<div class="catheader">
<h3 class="pagetitle<?php dor_print_category_title_class($dor_cat_id); ?>"><a href="<?php echo get_category_link($dor_cat_id); ?>" rel="bookmark"><?php echo $dor_cat_name; ?></a></h3>
<a href="<?php echo get_category_link($dor_cat_id); ?>/feed" class="feedlink" rel="nofollow" title="<?php echo $dor_cat_name; ?>-Newsfeed"><span class="printonly">Feed für <?php echo $dor_cat_name; ?>-Kategorie</span><img src="<?php bloginfo('template_directory'); ?>/img/feed-icon.png" width="16" height="16" alt="" class="feedicon" /></a>
</div>
<div class="entry"><ul class="categoryListExtended">
<?php
// output the posts
$dor_counter = 0;
while ($wp_query->have_posts()) : $wp_query->the_post();
$dor_counter++;
if ($dor_counter < 6) {
?>
<li>
<h4><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanenter Link zu <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
<small><?php the_author_link(); ?> am <?php the_time('j. F Y') ?> um <?php the_time('H:i') ?> Uhr<?php dor_the_rating(', <span class="rating">Bewertung: ', '</span>'); ?></small>
<?php if ($dor_counter == 1) { ?>
<div class="entry">
<?php dor_the_excerpt('<span class="invisible">Beitrag "' . the_title('', '', false) . '" </span>weiterlesen', 'den ganzen Beitrag lesen', true, '[', ']'); ?>
</div>
<p class="postmetadata">
<?php the_tags('Tags: ', ', ', ' <strong>|</strong>'); ?>
<?php comments_popup_link('0 Kommentare', '1 Kommentar', '% Kommentare', 'licomment'); ?>
<?php edit_post_link('Bearbeiten', '<strong>|</strong> ', ''); ?>
</p>
<?php } /* end if */ ?>
</li>
<?php
}
endwhile;
?>
</ul></div>
<?php
if ($dor_counter == 6) {
?>
<div class="spaced"><div class="wp-pagenavi"><a href="<?php echo get_category_link($dor_cat_id); ?>">weitere Beiträge...</a></div></div>
<?php
} /* end if more posts */
?>
<?php
} /* end if posts for category */
} /* end for categories */
// restore the original query
$wp_query = $original_query;
?>
</div></div>
<!-- end content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Alles anzeigen
Na ok, weil ich die Funktion gerade gesehen habe und das ohne ja nicht viel Sinn macht noch dieser Ausschnitt aus der functions.php:
/**
* Returns the title of the category with the given ID. Equals the function
* single_cat_title, but can return the title of any category and doesn't echo
* it.
*
* @param catId The ID of a category.
* @return The name of the category with the given ID or an empty String.
*/
function dor_the_category_name($catId) {
if (!empty($catId)) {
$my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID(intval($catId)));
if (!empty($my_cat_name)) {
return strip_tags($my_cat_name);
}
}
return '';
}
Alles anzeigen