Recent Topics

1 Jun 02, 2009 00:40    

My b2evolution Version: 2.x

I want my category tags to show how many posts are in that category, like this:

Basil (2)
Beef (5)
Cheese (3)
Dessert (9)
etc...

Is this possible?

2 Jun 02, 2009 07:35

Are you ready for another hack? :)

In inc/generic/model/_genericcategorycache.class.php, line 334 edit the following code

foreach( $cat_array as $cat )
{
	if( is_array( $callbacks['line'] ) )
	{ // object callback:
		$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
	}
	else

to

foreach( $cat_array as $cat )
{
	if( is_array( $callbacks['line'] ) )
	{ // object callback:
		$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
		
		$SQL = 'SELECT COUNT( postcat_post_ID )
				FROM T_postcats
				INNER JOIN T_items__item ON post_ID = postcat_post_ID
				WHERE postcat_cat_ID = '.$cat->ID.'
				AND post_status = "published" AND post_datestart < NOW()';
		
		if( !is_admin_page() && $post_count = $DB->get_var($SQL) )
		{
			$r .= ' ('.$post_count.')';
		}
	}
	else

You must also add global $DB; to the very top of this function

function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{
	global $DB;
	
	// Make sure children have been revealed for specific subset:

3 Jun 02, 2009 10:19

thanks... needed this hack

4 Jun 02, 2009 13:18

Can I assume this is a general hack for all skins? Since it's in the /inc folder?

Thanks!

5 Jun 02, 2009 14:02

hudson2001 wrote:

Can I assume this is a general hack for all skins? Since it's in the /inc folder?

Thanks!

yes it's a universal hack..

btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?

6 Jun 02, 2009 15:25

tilqicom wrote:

btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?

I didn't find it.

7 Jun 02, 2009 15:30

sam2kb wrote:

tilqicom wrote:

btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?

I didn't find it.

me niether :D

8 Jun 02, 2009 16:05

I know I did the first part right, so I must have put the global thing in the wrong place because I am getting this (and variations) on all my blogs:


Parse error: syntax error, unexpected $end in /home/jhudson2/domains/hudson2001.com/public_html/blogs/inc/generic/model/_genericcategorycache.class.php on line 451

Where PRECISELY does that global part need to go? I've tried it in a few places and nothing is working.

I hate being stupid about CSS.

9 Jun 02, 2009 16:11

Put

global $DB;

between the

function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{

and

// Make sure children have been revealed for specific subset:
$this->reveal_children( $subset_ID );

Line 248

Here's the whole updated function

/**
 * Return recursive display of loaded categories
 *
 * @param array callback funtions (to format the display)
 * @param integer|NULL NULL for all subsets
 * @param array categories list to display
 * @param int depth of  categories list
 *
 * @return string recursive list of all loaded categories
 */
function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{
	global $DB;
	
	// Make sure children have been revealed for specific subset:
	$this->reveal_children( $subset_ID );

	if( is_null( $cat_array ) )
	{	// Get all parent categories:
		if( is_null( $subset_ID ) )
		{
			$cat_array = $this->root_cats;
		}
		elseif( isset( $this->subset_root_cats[$subset_ID] ) )
		{	// We have root cats for the requested subset:
			$cat_array = $this->subset_root_cats[$subset_ID];
		}
		else
		{
			$cat_array = array();
		}
	}

	$r = '';

	if( is_array( $callbacks['before_level'] ) )
	{ // object callback:
		$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
	}
	else
	{
		$r .= $callbacks['before_level']( $level ); // <ul>
	}

	foreach( $cat_array as $cat )
	{
		if( is_array( $callbacks['line'] ) )
		{ // object callback:
			$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			
			$SQL = 'SELECT COUNT( postcat_post_ID )
					FROM T_postcats
					INNER JOIN T_items__item ON post_ID = postcat_post_ID
					WHERE postcat_cat_ID = '.$cat->ID.'
					AND post_status = "published" AND post_datestart < NOW()';
			
			if( !is_admin_page() && $post_count = $DB->get_var($SQL) )
			{
				$r .= ' ('.$post_count.')';
			}
		}
		else
		{
			$r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
		}

		if( !empty( $cat->children ) )
		{	// Add children categories:
			$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
		}
		elseif( is_array( $callbacks['no_children'] ) )
		{ // object callback:
			$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
		}
		else
		{
			$r .= $callbacks['no_children']( $cat, $level ); // </li>
		}

	}

	if( is_array( $callbacks['after_level'] ) )
	{ // object callback:
		$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
	}
	else
	{
		$r .= $callbacks['after_level']( $level ); // </ul>
	}

	return $r;
}

10 Jun 02, 2009 16:23

Ah, it makes sense now.

/smacks head

I was trying to insert the entire thing, not just the global $DB; part.

Now it works like a charm! Wheeeeeeee!

I should say...on most of my blogs. On Pixel Green it's screwed up. Thoughts? More hacks? :)

http://www.hudson2001.com/blogs/index.php/baby/

11 Jun 14, 2009 02:24

i have tried this but it is not working for me..
My install version is 2.4.5

i have replaced these lines:

		// Make sure children have been revealed for specific subset:
		$this->reveal_children( $subset_ID );

		if( is_null( $cat_array ) )
		{	// Get all parent categories:
			if( is_null( $subset_ID ) )
			{
				$cat_array = $this->root_cats;
			}
			elseif( isset( $this->subset_root_cats[$subset_ID] ) )
			{	// We have root cats for the requested subset:
				$cat_array = $this->subset_root_cats[$subset_ID];
			}
			else
			{
				$cat_array = array();
			}
		}

		$r = '';

		if( is_array( $callbacks['before_level'] ) )
		{ // object callback:
			$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
		}
		else
		{
			$r .= $callbacks['before_level']( $level ); // <ul>
		}

		foreach( $cat_array as $cat )
		{
			if( is_array( $callbacks['line'] ) )
			{ // object callback:
				$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			}
			else
			{
				$r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			}

			if( !empty( $cat->children ) )
			{	// Add children categories:
				$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
			}
			elseif( is_array( $callbacks['no_children'] ) )
			{ // object callback:
				$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
			}
			else
			{
				$r .= $callbacks['no_children']( $cat, $level ); // </li>
			}

		}

		if( is_array( $callbacks['after_level'] ) )
		{ // object callback:
			$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
		}
		else
		{
			$r .= $callbacks['after_level']( $level ); // </ul>
		}

		return $r;
	}

with the following you gave:

/**
* Return recursive display of loaded categories
*
* @param array callback funtions (to format the display)
* @param integer|NULL NULL for all subsets
* @param array categories list to display
* @param int depth of categories list
*
* @return string recursive list of all loaded categories
*/
function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{
global $DB;

// Make sure children have been revealed for specific subset:
$this->reveal_children( $subset_ID );

if( is_null( $cat_array ) )
{ // Get all parent categories:
if( is_null( $subset_ID ) )
{
$cat_array = $this->root_cats;
}
elseif( isset( $this->subset_root_cats[$subset_ID] ) )
{ // We have root cats for the requested subset:
$cat_array = $this->subset_root_cats[$subset_ID];
}
else
{
$cat_array = array();
}
}

$r = '';

if( is_array( $callbacks['before_level'] ) )
{ // object callback:
$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
}
else
{
$r .= $callbacks['before_level']( $level ); // <ul>
}

foreach( $cat_array as $cat )
{
if( is_array( $callbacks['line'] ) )
{ // object callback:
$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category - or - <tr><td>Category</td></tr> ...

$SQL = 'SELECT COUNT( postcat_post_ID )
FROM T_postcats
INNER JOIN T_items__item ON post_ID = postcat_post_ID
WHERE postcat_cat_ID = '.$cat->ID.'
AND post_status = "published" AND post_datestart < NOW()';

if( !is_admin_page() && $post_count = $DB->get_var($SQL) )
{
$r .= ' ('.$post_count.')';
}
}
else
{
$r .= $callbacks['line']( $cat, $level ); // <li> Category - or - <tr><td>Category</td></tr> ...
}

if( !empty( $cat->children ) )
{ // Add children categories:
$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
}
elseif( is_array( $callbacks['no_children'] ) )
{ // object callback:
$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
}
else
{
$r .= $callbacks['no_children']( $cat, $level ); // </li>
}

}

if( is_array( $callbacks['after_level'] ) )
{ // object callback:
$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
}
else
{
$r .= $callbacks['after_level']( $level ); // </ul>
}

return $r;
}

12 Jun 14, 2009 07:09

Edit this part and see if it changes the output.
Or maybe it doesn't work in 2.4.5 :-/ , let me check...

        }
        else
        {
            $r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
        }

        if( !empty( $cat->children ) )
        {    // Add children categories:

        }
        else
        {
            $r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
            $r .= ' (blah)';
        }

        if( !empty( $cat->children ) )
        {    // Add children categories: 

13 Jun 14, 2009 16:54

For those who do core work, it would be nice if each category had a field for total number of posts. Back in the day cat lists always showed number of posts, but it was taken out for server efficiency - doing the query each time yah? So we can put it back by putting the querying back, but wouldn't it be nice if at create/edit/delete a little counter was updated?

Then maybe don't show cats with no posts and probably have a param that lets one turn off the posts-in-cat counter, but really getting an efficient counter back would be nice.

14 Jun 26, 2009 01:19

i have been able to get around this one.thanks.

However i have a specific problem as always...

see screenshot below:

http://i43.tinypic.com/2e5tmp5.jpg

the thing is i have 4 parent categories as you see there:

Kişiler - (People)
Konular - (Topics)
Meslekler- (Professions)
Ülkeler- (Nations)

These categories aren't meant to be selected during entering a new post, they were only covers but i have selected one of those -konular- by mistake and now it appears Konular (1) as you can see..I dont know how i can detect in which post i have selected it, and as this parent cat includes all the other sub cats, there are hundreds of posts under it and it all appears when i click it, is there anyway how i can determine which is that 1 post causing it ?

16 Jun 26, 2009 15:04

no help. |: since it seems i have checked that -konular- as an extra cat but not the main cat..

edit: nevermind, i have sorted it out by going through all the posts one by one.. luckily i had a few hundred posts and found it in the half way, it was quite an arse in the pain though, thanks


Form is loading...