View Single Post
Old 12-06-2007, 01:58 PM   #26 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

The whole plugin page looks like:

Code:
<?php

/*

Plugin Name: Posts By Category

Plugin URI: http://win.frucomerci.com/includes/PostsbyCategory.txt

Description: Displays a list of the post titles in each category.

Author: Frucomerci

Version: 2.0

Author URI: http://www.frucomerci.com/list-posts-by-category-plugin-for-wordpress/

*/



 // Setup defaults if options do not exist

add_option('pc_header', '<h2>Posts by category</h2>');


function pc_add_option_pages() {

	if (function_exists('add_options_page')) {

		add_options_page('List Posts by Categories', 'Posts by category', 8, __FILE__, 'pc_options_page');

	}		

}



function pc_options_page() {

	if (isset($_POST['info_update'])) {



		?>

<div id="message" class="updated fade"><p><strong><?php 



		update_option('pc_header', (string) $_POST["pc_header"]);

		echo "Configuration Updated!";



	    ?></strong></p></div><?php



	} ?>



	<div class=wrap>



	<h2>Posts by Category</h2>



	<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">

	<input type="hidden" name="info_update" id="info_update" value="true" />





	<fieldset class="options"> 

	  <legend>Options</legend>

	  <table width="100%" border="0" cellspacing="0" cellpadding="6">



	  <tr valign="top"><td width="35%" align="right">

		  Header text

	  </td><td align="left">

		  <input name="pc_header" type="text" size="50" value="<?php echo get_option('pc_header') ?>"/>

	  </td></tr>

	  </table>

	</fieldset>



	<div class="submit">

		<input type="submit" name="info_update" value="<?php _e('Update options'); ?> &raquo;" />

	</div>

	</form>

	</div>

    <?php

}


function posts_by_category() {

$number = "4";



	global $wpdb, $post;



	$tp = $wpdb->prefix;



	$pc_header = get_option('pc_header');



	$sort_code = 'ORDER BY name ASC, post_date DESC';

	$the_output = NULL;





	$last_posts = (array)$wpdb->get_results("

		SELECT {$tp}terms.name, {$tp}terms.term_id

		FROM {$tp}terms, {$tp}term_taxonomy

		WHERE {$tp}terms.term_id = {$number}

                AND {$tp}term_taxonomy.taxonomy = 'category'

		{$hide_check} 

	");



	if (empty($last_posts)) {

		return NULL;

	}



	$the_output .= stripslashes($ddle_header); 



	$used_cats = array();;

	$i = 0;

	foreach ($last_posts as $posts) {

		if (in_array($posts->name, $used_cats)) {

			unset($last_posts[$i]);

		} else {

			$used_cats[] = $posts->name;

		}

		$i++;

	}

	$last_posts = array_values($last_posts);



	foreach ($last_posts as $posts) {

$the_output .='<div class="col">';

	  $the_output .= '<h2>' . apply_filters('list_cats', $posts->name, $posts) . '</h2>';



          $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'" , $r );

    

 $arcresults = $wpdb->get_results("SELECT *, COUNT( `ID` ) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select object_id FROM {$tp}term_relationships, {$tp}terms WHERE {$tp}term_relationships.term_taxonomy_id ={$number}) GROUP BY 1 ORDER BY post_date DESC LIMIT 0 , 5;");
		  
		//. $posts->term_id .

			$the_output .= '<ul class="latestmenu">';

	  foreach ( $arcresults as $arcresult ) {

	       $the_output .= '<li><a href="' . get_permalink($arcresult->ID) . '">' . apply_filters('the_title', $arcresult->post_title) . '</a></li>';

	   }

    

          $the_output .= '';

       }

       $the_output .= '</ul></div>';

       return $the_output;

}

function pc_generate($content) {

	$content = str_replace("<!-- postsbycategory -->", posts_by_category(), $content);

	return $content;

}

add_filter('the_content', 'pc_generate');

add_action('admin_menu', 'pc_add_option_pages'); 


?>
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote