
Da ich persönlich danach gefragt wurde, wie ich denn auf meiner Startseite das Auflisten der letzten Beiträge je Kategorie bewerkstelligt habe, stelle ich einfach mal den Code-Schnipsel aus dem Theme hier zur Verfügung.
Ich nenne das Ganze einfach mal DCN CatLooper.
Der Code ist zwar für WordPress ausgelegt, kann aber sicher auch als Vorlage für andere CMS/Blogsysteme dienen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <?php /** * DCN CatLooper * * Das folgende Code-Snippet dient in einem Wordpress-Theme der spaltenweise Ausgabe von Beitraegen je (ausgewaehlter) Kategorie fuer die Startseite. * Example on/Beispiel auf: http://blogcraft.de (indexpage, under the top post) * * The following code snippet is for usage in a Wordpress theme file. * It is a looping example for the output of items in a row of selected categories. * * Code snippet is licensed under a Creative Commons licence - CC-BY-3.0-DE * * @author Christoph Grabo <blogcrafter@blogcraft.de> * @link http://blogcraft.de/b/technik/snippets/schleife-fuer-beitraege-je-kategorie CatLooper Description (german) * @version 1.0 * @copyright Copyright (c) 2010, Christoph Grabo * @licence http://creativecommons.org/licenses/by/3.0/de/ Creative Commons BY 3.0 DE */ ?> <div id="catlooper"> <?php $dcn_catloop = array( 1 => "Kategorie1", 2 => "Kategorie2", 3 => "Kategorie3" ); /* DE: Fuer jede Spalte die Kategorie-ID und gewuenschte Überschrift EN: for every row give here the category ID and a good headline name */ $dcn_catitems_max = 3; /* DE: gewuenschte Anzahl der Beitraege je Kategorie um 1 reduziert! (da Schleife bei 0/Null anfaengt) EN: desired count of items per category minus 1 (loop counting starts with zero!) */ foreach($dcn_catloop as $dcn_catloop_id => $dcn_catloop_name) { ?> <div class="dcn-catrow"> <h3 class="dcn-cattitle"><a href="<?php echo get_category_link($dcn_catloop_id); ?>"><?php echo $dcn_catloop_name; ?></a></h3> <p class="dcn-catdescr"><?php echo category_description($dcn_catloop_id); ?></p> <?php $dcn_category = new WP_Query('showposts='.($dcn_catitems_max+1).'&cat='.$dcn_catloop_id); $dcn_loopcounter = 0; while ($dcn_category->have_posts()) : $dcn_category->the_post(); $dcn_loopcounter++; update_post_caches($posts); //if( get_the_ID() === $top_post_id ) { $loopcounter--; continue; } /* $top_post_id Abfrage/query: DE: auskommentieren, falls man ueber dieser Schleife noch einen grossen angeteaserten Post benutzen moechte (siehe auf blogcraft.de) EN: comment this out if you don't want to have repeated the teaser post on index (like on blogcraft.de) */ ?> <div class="dcn-catpost"> <h4 class="dcn-catpost-header"><a href="<?php the_permalink() ?>" title="permalink zu »<?php the_title(); ?>«"><?php the_title(); ?></a></h4> <p class="dcn-catpost-entry"> <?php the_excerpt(); /* oder deine Alternative / or alternative */ ?> </p> <p class="dcn-catpost-readmore"><a href="<?php the_permalink() ?>#more" title="weiterlesen von '<?php the_title(); ?>' ..."> </a></p> </div> <?php if($dcn_loopcounter == $dcn_catitems_max) break; endwhile; //of while(have_posts() ...) ?> </div> <?php }; //end of cat loop ?> </div> |
Ich habe den Code zum einfacheren Übernehmen als Datei hinterlegt: dcn-catlooper.php
Einfach mit Rechtsklick “Speichern unter …” auswählen, abspeichern und die Dateiendung auf .php reduzieren (oder Code gleich in den richtigen Abschnitt des Themes kopieren).
Viel Spaß damit!
