10.09.2008, 12:16
|
#1 (permalink)
| | PostRank: 1
Registriert seit: 21.12.2006
Beiträge: 42
| Kategorien auf statischer Seite anzeigen mit Inhaltsverzeichnis Es gab hier mal einen Thread, mit diesem Thema. Ich wollte dies aber nicht als Template,sondern als Plugin, also noch ein bisschen komfortabler, variabler, mit Inhaltsverzeichnis für die Artikel und Auswahl, welche Kategorien angezeigt werden sollen.
Habe bereits ein Plugin geschrieben, welches auch fast fertig ist.
Da einzige Problem ist jetzt, dass "older posts" usw. nicht funktioniert. Es werden gleich alle Artikel ausgegeben und demzufolge gibt die Seite ..."page/2/" wieder nur alle Artikel aus....
Hier der Quellcode (Achtung: Beta Version und das Script habe ich entwickelt, also meinen Namen belassen!): PHP-Code: <?php /* Plugin Name: Show category on page Plugin URI: http://www.mi-schi.com/wordpress/plugins/show-category-on-page/ Description: Mit diesem Plugin kann man alle oder nur bestimmte Kategorien auf einer statischen Seite anzeigen lassen. Einfach in das Textfeld der statischen Seite "[ShowCategory]" (alle Kategorien) oder "[ShowCategory=x,x]" (nur bestimmte kategorien) einfügen. Weiterhin kann mit "[I:ShowCategory]" oder "[I:ShowCategory=x,x]" zusätzlich das Inhaltsverzeichnis von allen Beiträgen der Kategorie(n) am Anfang der Seiten mit angezeigt werden. Version: 1.0 Author: Michael Schindler Author URI: http://www.mi-schi.com/
--------------------------------------------------------------------- Das Plugin "Show category on page" steht unter der GNU General Public License.
Hier kann man die GNU General Public License nachlesen: <http://www.gnu.org/licenses/> --------------------------------------------------------------------- */
add_filter('the_content', 'scop_filter'); load_plugin_textdomain('scop','wp-content/plugins/show-category-on-page/lang'); include('my-theme-loop.inc.php');
function scop_filter($content) { if(preg_match('/\[(I:)?ShowCategory\]/',$content)) { if (preg_match('/\[I:ShowCategory\]/',$content)) { $content = str_replace('[I:ShowCategory]', scop('all', 'index'), $content); } else { $content = str_replace('[ShowCategory]', scop('all'), $content); } } elseif (preg_match('/\[(?:I:)?ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/',$content,$treffer)) { if (preg_match('/\[I:ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/',$content)) { $content = preg_replace('/\[I:ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/', scop('part', 'index', $treffer['1']), $content); } else { $content = preg_replace('/\[ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/', scop('part', 'null', $treffer['1']), $content); } } return $content; } function scop($handle, $index='null', $treffer='null') { if ($handle == 'part' && $treffer != 'null') { query_posts('cat=' . $treffer); } else { query_posts('cat=0'); } if ($index == 'index') { echo "<h2>" . __('Inhaltsverzeichnis:', 'scop') . "</h2>\n"; echo "<ul id=\"toc-index\">\n"; if (have_posts()) : while (have_posts()) : the_post(); echo '<li><a href="'; the_permalink(); echo '" rel="bookmark">'; the_title(); echo "</a></li>\n"; endwhile; else: echo "<li>" . __('Es wurden keine Artikel gefunden.', 'scop') . "</li>"; endif; echo "</ul>"; } if (function_exists('my_theme_loop')) { my_theme_loop(); } else { // Original-Loop vom Theme "Cassic" ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_date('','<h2>','</h2>'); ?>
<div class="post" id="post-<?php the_ID(); ?>"> <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
<div class="storycontent"> <?php the_content(__('(more...)')); ?> </div>
<div class="feedback"> <?php wp_link_pages(); ?> <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?> </div>
</div>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
<?php posts_nav_link(' — ', __('« Newer Posts'), __('Older Posts »')); ?>
<?php } }
?> PHP-Code: <?php /* Hier bitte in die Funtkion my_theme_loop() deinen Theme-Loop aus der index.php-Datei einfügen, um eine gleiche Darstellung auf den statischen Seiten zu erhalten.
Du kannst nicht PHP? Einfach den folgenden Syntax verwenden und nach dem "* /" mit einfügen:
function my_theme_loop() { ?>
Hier diesen text mit deinem Theme-Loop ersetzen.
<?php } */
function my_theme_loop() { ?>
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
<div class="post-header"> <span class="dateicon"> <span class="dateicon-month"><?php the_time('M') ?></span> <span class="dateicon-day"><?php the_time('j') ?></span> </span> <div class="titlearea"><h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1> <div class="post-info"><span class="alignleft"><img src="<?php bloginfo('template_url'); ?>/images/caticon.gif" alt="" /> <?php the_category(', '); ?> <?php if (get_the_tags()) the_tags('<span class="tags">', ', ', '</span>'); ?><?php edit_post_link('bearbeiten', ' | ', ''); ?></span><span class="alignright"><img src="<?php bloginfo('template_url'); ?>/images/comicon.gif" alt="" /> <?php comments_popup_link('Add Comment (0)', 'Add Comment (1)', 'Add Comment (%)'); ?></span> </div> </div> </div> <?php the_content('Read More'); ?> <br />
<?php endwhile; ?> <div class="navigation"> <span class="alignleft"><?php posts_nav_link('','','« Older Posts') ?></span> <span class="alignright"><?php posts_nav_link('','Newer Posts »','') ?></span> </div> <?php else : ?> <h1>Die angeforderte Seite ist nicht vorhanden.</h1> <p>Die Seite wurde entweder verschoben, umbenannt oder gelöscht.</p> <p><a href="<?php echo get_bloginfo('url'); ?>">zur Startseite</a></p> <?php endif; ?>
<?php } ?> |
| |
12.09.2008, 17:12
|
#3 (permalink)
| | PostRank: 1
Registriert seit: 21.12.2006
Beiträge: 42
| Kann mir denn niemand helfen, wie man einen Loop in Loop erstellt über ein Plugin? |
| |
12.09.2008, 21:14
|
#4 (permalink)
| | WPD-Team
Registriert seit: 04.06.2005 Ort: INET
Beiträge: 8.151
| Hi ich gab Dir grade die Antwort auf texto.de ...
lg |
| |
12.09.2008, 21:26
|
#5 (permalink)
| | PostRank: 1
Registriert seit: 21.12.2006
Beiträge: 42
| Habe ja deinen Code genommen: PHP-Code: <?php /* Plugin Name: Show category on page Plugin URI: http://www.mi-schi.com/wordpress/plugins/show-category-on-page/ Description: Mit diesem Plugin kann man alle oder nur bestimmte Kategorien auf einer statischen Seite anzeigen lassen. Einfach in das Textfeld der statischen Seite "[ShowCategory]" (alle Kategorien) oder "[ShowCategory=x,x]" (nur bestimmte kategorien) einfügen. Weiterhin kann mit "[I:ShowCategory]" oder "[I:ShowCategory=x,x]" zusätzlich das Inhaltsverzeichnis von allen Beiträgen der Kategorie(n) am Anfang der Seiten mit angezeigt werden. Version: 1.0 Author: Michael Schindler Author URI: http://www.mi-schi.com/
--------------------------------------------------------------------- Das Plugin "Show category on page" steht unter der GNU General Public License.
Hier kann man die GNU General Public License nachlesen: <http://www.gnu.org/licenses/> --------------------------------------------------------------------- */
add_filter('the_content', 'scop_filter'); load_plugin_textdomain('scop','wp-content/plugins/show-category-on-page/lang'); include('my-theme-loop.inc.php');
function scop_filter($content) { if(preg_match('/\[(I:)?ShowCategory\]/',$content)) { if (preg_match('/\[I:ShowCategory\]/',$content)) { $content = str_replace('[I:ShowCategory]', scop('all', 'index'), $content); } else { $content = str_replace('[ShowCategory]', scop('all'), $content); } } elseif (preg_match('/\[(?:I:)?ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/',$content,$treffer)) { if (preg_match('/\[I:ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/',$content)) { $content = preg_replace('/\[I:ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/', scop('part', 'index', $treffer['1']), $content); } else { $content = preg_replace('/\[ShowCategory=([0-9]+(?:,?[0-9]+)*)\]/', scop('part', 'null', $treffer['1']), $content); } } return $content; } function scop($handle, $index='null', $treffer='null') { /* if ($handle == 'part' && $treffer != 'null') { query_posts("cat=$treffer&paged=$paged"); } else { query_posts("cat=0&paged=$paged"); } if ($index == 'index') { echo "<h2>" . __('Inhaltsverzeichnis:', 'scop') . "</h2>\n"; echo "<ul id=\"toc-index\">\n"; if (have_posts()) : while (have_posts()) : the_post(); update_post_caches($posts); echo '<li><a href="'; the_permalink(); echo '" rel="bookmark">'; the_title(); echo "</a></li>\n"; endwhile; else: echo "<li>" . __('Es wurden keine Artikel gefunden.', 'scop') . "</li>"; endif; echo "</ul>"; } if (function_exists('my_theme_loop')) { my_theme_loop(); } else { if (have_posts()) : while (have_posts()) : the_post(); the_title('<h3>', '</h3>'); the_date('','<h2>','</h2>'); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
<div class="storycontent"> <?php the_content(__('(more...)')); ?> </div>
<div class="feedback"> <?php wp_link_pages(); ?> <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?> </div>
</div>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
<?php posts_nav_link(' — ', __('« Newer Posts'), __('Older Posts »')); ?>
<?php } */ ?> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('cat=0&showposts=1'.'&paged='.$paged); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php the_title('<h3>', '</h3>'); ?>
<?php endwhile; ?>
<?php next_posts_link('« ältere Artikel') ?> <?php previous_posts_link('neuere Artikel »') ?>
<?php $wp_query = null; $wp_query = $temp;?> <?php } ?> Ausgabe ist aber lediglich: Zitat: News & Partypics 2. testartikel
bearbeiten | Da fehlt eben der Link zum Seiten-Wechsel 
gerade noch mal mit "page/2/" getestet, funktioniert auch nicht, wird wieder nur der "2. Testartikel" ausgegeben und nicht der vorhergehende Artikel "test"
Geändert von mi-schi (12.09.2008 um 21:28 Uhr).
|
| |
15.10.2008, 17:21
|
#6 (permalink)
| | PostRank: 0
Registriert seit: 04.01.2008
Beiträge: 9
| Gibt es das Plugin irgendwo?
Ich möchte ebenfalsl alle Kategorien auf einer Seite auflsiten.... |
| | | Themen-Optionen | | | | Ansicht | Linear-Darstellung |
Forumregeln
| Es ist dir nicht erlaubt, neue Themen zu verfassen. Es ist dir nicht erlaubt, auf Beiträge zu antworten. Es ist dir nicht erlaubt, Anhänge hochzuladen. Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten. HTML-Code ist aus. | | | Alle Zeitangaben in WEZ +1. Es ist jetzt 19:11 Uhr. | |