TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-06-2007, 01:31 PM   #21 (permalink)
The Contributor
Good Samaritan 
 
d4v1d's Avatar
 
Join Date: Dec 2007
Location: Durban, South Africa
Posts: 51
Thanks: 1
d4v1d is on a distinguished road
Default

I think i found the problem for no value being passed... there is a second function calling the previous function:

PHP Code:
function pc_generate($content) {

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

    return 
$content;


I'm not entirely sure how everything ties up...

EDIT: If you're entirely sure it worked with the constant, then you have to edit all instances of of the function call to include the 4...

For instance, the above function would need to change to:

PHP Code:
function pc_generate($content) {

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

    return 
$content;


This should eliminate the apparent function clash you have now.
d4v1d is offline  
Reply With Quote
Old 12-06-2007, 01:44 PM   #22 (permalink)
The Contributor
Upcoming Programmer 
 
Matt83's Avatar
 
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
Matt83 is on a distinguished road
Default

Quote:
Originally Posted by d4v1d View Post
I think i found the problem for no value being passed... there is a second function calling the previous function:

PHP Code:
function pc_generate($content) {

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

    return 
$content;


I'm not entirely sure how everything ties up...
ahh i missed that . Good find

Then i would suggest to modify that function to:

PHP Code:
function pc_generate($content,$number) {

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

    return 
$content;



And simply call:

PHP Code:
pc_generate($theContentVariable,4); 
__________________
http://www.mattvarone.com
Matt83 is offline  
Reply With Quote
Old 12-06-2007, 01:44 PM   #23 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

I think that second one is the find and replace function for wordpress.
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 12-06-2007, 01:49 PM   #24 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

I'm lost now lol.

Getting an error saying:
Code:
Warning: Missing argument 2 for pc_generate() in /home/filmzone/public_html/wp-content/plugins/postsbycategory.php on line 230

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND wp_term_taxonomy.taxonomy = 'category'' at line 7]
SELECT wp_terms.name, wp_terms.term_id FROM wp_terms, wp_term_taxonomy WHERE wp_terms.term_id = AND wp_term_taxonomy.taxonomy = 'category'
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 12-06-2007, 01:52 PM   #25 (permalink)
The Contributor
Good Samaritan 
 
d4v1d's Avatar
 
Join Date: Dec 2007
Location: Durban, South Africa
Posts: 51
Thanks: 1
d4v1d is on a distinguished road
Default

I think we're looking at this out of context... could you quote the entire block of code that's calling all the functions you're using so we have a better idea of whats going on.
d4v1d is offline  
Reply With Quote
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
Old 12-06-2007, 03:50 PM   #27 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

Nobody lol?

Is there a way I could change the sql to fetch lists back from 3 categories instead then?
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 12-06-2007, 03:56 PM   #28 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

I've fixed it. That plugin waaaaayyy overcomplicates everything lol.
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 12-06-2007, 03:59 PM   #29 (permalink)
The Contributor
Good Samaritan 
 
d4v1d's Avatar
 
Join Date: Dec 2007
Location: Durban, South Africa
Posts: 51
Thanks: 1
d4v1d is on a distinguished road
Default

lol What did you do?
d4v1d is offline  
Reply With Quote
Old 12-06-2007, 04:07 PM   #30 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

I found some code that does the same thing in about 6 lines lol:
Code:
<?php
 $myposts = get_posts('numberposts=5&offset=0&category=3');
 foreach($myposts as $post) :
 ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 <?php endforeach; ?>
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 12-06-2007, 04:17 PM   #31 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Heh! Now you've sorted it, can I remark on the use of Wordpress' globals? Have they never heard of classes?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design