snowcrab302
Forum Replies Created
-
Forum: Plugins
In reply to: next and previous links in one specific categoryI ended up modifying an existing plugin by Scriptygoddess. It seems to work…
<?php
/*
Plugin Name: Next/Previous Post in specific Category
Version: v 0.1
Plugin URI:
Description: This plugin will give you two functions that will give you links to the next/previous post in a specific category.
Author: hani - based on the plugin by Jennifer - Scriptygoddess
Author URI:*/
/*
examples of use:
previous_specCat(13,'', '', '', '', false, '« previous');
next_specCat(13,'', '', '', '', false, 'next »');*/
function previous_specCat($specCat,$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;
//get post id of previous post
$previousPostId = $wpdb->get_var("SELECT post_id from $tablepost2cat, $tableposts WHERE category_id = $specCat 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 = $specCat");
$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_specCat($specCat, $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;/* -------------------------------------------------- */
$nextPostId = $wpdb->get_var("SELECT post_id from $tablepost2cat, $tableposts WHERE category_id = $specCat 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 = $specCat");
$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;
}
}/* --------------------------------------- */
}
?>Forum: Fixing WordPress
In reply to: where is the code generated for images in posts?Thanks so much! That solved the problem perfectly.