', $afterGroup='', $beforeEach='
  • ', $afterEach='
  • ', $showtitle=true, $textForEach='Previous post in %:
    ') { 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."".stripslashes($previousPostInfo->post_title)."".$afterEach; } else { echo $beforeEach."".$leaderText."".$afterEach; } } } if (!$startGroup) { echo $afterGroup; } } function next_cat_post($beforeGroup='', $beforeEach='
  • ', $afterEach='
  • ', $showtitle=true, $textForEach='Next post in %:
    ') { 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."".stripslashes($nextPostInfo->post_title)."".$afterEach; } else { echo $beforeEach."".$leaderText."".$afterEach; } } } if (!$startGroup) { echo $afterGroup; } } ?>