hallo zusammen,
ich wollte dies bei mir auch einbauen, habe da mal ein bisschen gesucht und folgendes gefunden auf einer website, weiss nur nicht mehr auf welcher - sorry ...
aber ne Seite steht ja im Plugin ...
<?php
/*
Plugin Name: Next/Previous Post in same Category
Version: v 0.2
Plugin URI: http://www.scriptygoddess.com/archives/2004/07/24/nextprevious-posts-in-same-category/
Description: This plugin will give you two functions that will give you links to the next/previous post in the same category as the current post.
Author: Jennifer - Scriptygoddess
Author URI: http://scriptygoddess.com
supports up2date plugin
http://software.vtpaintball.net/wordpress/up2date.php
*/
/*
up2date support
*/
if( function_exists( 'u2d_register_plugin' ) ) {
u2d_register_plugin( "Next/Previous Post in same Category", "http://www.scriptygoddess.com/up2date/nextPreviousCatCurrent.txt", "0.2", 3);
}
function previous_cat_post($beforeGroup='<ul>', $afterGroup='</ul>', $beforeEach='<li>', $afterEach='</li>', $showtitle=true, $textForEach='Previous post in %:<br />') {
global $wpdb, $tableposts, $tablepost2cat, $tablecategories, $post;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
if (!isset($tablepost2cat))
$tablepost2cat = $wpdb->post2cat;
if (!isset($tablecategories))
$tablecategories = $wpdb->categories;
//get home url for base of link
$info = get_bloginfo('url');
$info = apply_filters('bloginfo', $info);
$homeurl = convert_chars($info);
//get post id of current post
$currentPostId = $post->ID;
//get cat id of current post
$currentCatIds = $wpdb->get_results("SELECT category_id FROM $tablepost2cat WHERE post_id = $currentPostId");
$startGroup = true;
foreach ($currentCatIds as $currentCatId) {
//get post id of previous post
$previousPostId = $wpdb->get_var("SELECT post_id from $tablepost2cat, $tableposts WHERE category_id = $currentCatId->category_id AND post_id < $currentPostId AND post_status = 'publish' AND post_id = ID ORDER BY post_id DESC LIMIT 1");
if ($previousPostId) {
$previousPostInfo = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = $previousPostId");
$previousCatInfo = $wpdb->get_row("SELECT cat_name FROM $tablecategories WHERE cat_ID = $currentCatId->category_id");
$leaderText = str_replace('%', $previousCatInfo->cat_name, $textForEach);
if ($startGroup) {
echo $beforeGroup;
$startGroup = false;
}
if ($showtitle) {
echo $beforeEach.$leaderText."<a href=\"".get_permalink($previousPostId)."\">".stripslashes($previousPostInfo->post_title)."</a>".$afterEach;
} else {
echo $beforeEach."<a href=\"".get_permalink($previousPostId)."\">".$leaderText."</a>".$afterEach;
}
}
}
if (!$startGroup) {
echo $afterGroup;
}
}
function next_cat_post($beforeGroup='<ul>', $afterGroup='</ul>', $beforeEach='<li>', $afterEach='</li>', $showtitle=true, $textForEach='Next post in %:<br />') {
global $wpdb, $tableposts, $tablepost2cat, $tablecategories, $post;
if (!isset($tableposts))
$tableposts = $wpdb->posts;
if (!isset($tablepost2cat))
$tablepost2cat = $wpdb->post2cat;
if (!isset($tablecategories))
$tablecategories = $wpdb->categories;
//get home url for base of link
$info = get_bloginfo('url');
$info = apply_filters('bloginfo', $info);
$homeurl = convert_chars($info);
//get post id of current post
$currentPostId = $post->ID;
//get cat id of current post
$currentCatIds = $wpdb->get_results("SELECT category_id FROM $tablepost2cat WHERE post_id = $currentPostId");
$startGroup = true;
foreach ($currentCatIds as $currentCatId) {
//get post id of next post
$nextPostId = $wpdb->get_var("SELECT post_id from $tablepost2cat, $tableposts WHERE category_id = $currentCatId->category_id AND post_id > $currentPostId AND post_status = 'publish' AND post_id = ID ORDER BY post_id ASC LIMIT 1");
if ($nextPostId) {
$nextPostInfo = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = $nextPostId");
$nextCatInfo = $wpdb->get_row("SELECT cat_name FROM $tablecategories WHERE cat_ID = $currentCatId->category_id");
$leaderText = str_replace('%', $nextCatInfo->cat_name, $textForEach);
if ($startGroup) {
echo $beforeGroup;
$startGroup = false;
}
if ($showtitle) {
echo $beforeEach.$leaderText."<a href=\"".get_permalink($nextPostId)."\">".stripslashes($nextPostInfo->post_title)."</a>".$afterEach;
} else {
echo $beforeEach."<a href=\"".get_permalink($nextPostId)."\">".$leaderText."</a>".$afterEach;
}
}
}
if (!$startGroup) {
echo $afterGroup;
}
}
?>
Alles anzeigen
also ich hoffe dies hilft, hoffe es funktioniert, kannst ja mal bescheid geben ...
V.