Recent Topics

1 Dec 18, 2008 08:47    

My b2evolution Version: 2.x

Hi,

I am attempting to add some coding to the sidebar that will display a different Amazon.com ad based on the chosen category.
I know a little bit about PHP and am pretty sure what I want to construct is an if / elseif statement. Something along the lines of -

<?php

if ( $category = "Music" )

   echo "Amazon coding here" ;

elseif ( $category = "Movies" )

   echo "Amazon coding here" ;

repeat for each category i need it for ---

   else die;
?>

I always have trouble with the variables part.

Can someone tell me if I am thinking along the right lines?

Is $category the variable I need to use with b2evo to call the category names?

Can I make it only check the main category of a post, rather than a sub-category?

Is echo the correct function I need?

Anyone willing to give me a blank template to use where I can just put in category name and the Amazon code? (To make sure I don't miss a simple ; or { and mess it all up. lol )

Thanks to anyone that can help,
Gene :-)

In case it matters I am using the Russian b2evolution skin.

2 Dec 18, 2008 13:06

It's a tad of a ballache to get $Item into the sidebar, but when you do you need to code something along the lines of :

<?php
switch( $Item->main_cst_ID )
{
  case 1 :
?>
<!-- your amazon code here -->
<?php
  break;

  case 2 :
?>
<!-- your amazon code here -->
<?php
  break;

/* repeat for all ID's */

  default :
?>
<!-- your amazon code here for categories not covered by the above -->
<?php
  break;
} // end switch()
?>

¥

3 Dec 18, 2008 13:19

Thanks ¥,

I knew I probably had it at least slightly off - now I see I was way off!

I do appreciate your help.

One question, I do need to use the category ID number listed in the admin area as Case, correct?

Thanks,
Gene :-)

Edit: ok, another question. Does the PHP plugin listed under downloads not work?

4 Dec 18, 2008 13:39

Yep @ cat ID

I've no idea if the php plugin works as I've never used it ;)

¥


Form is loading...