Page 1 of 1
Placing php code in a sidebar
Posted: Mon May 01, 2006 6:42 am
by MichaelParent
Hi.
I'm trying to use phpadnews to control baner advertisements on my blog site. I had found a similar post about using php in a sidebar. It was suggested to use the external php plug-in. But it seems that plug-in is NOT for the sidebars, but for Events. Am I mistaken?
Phpadnews can also create javascript for the banner. I tried that in the html nugget plug-in, but that did not work. Has anoyone else done this? Any suggestions?
Thanks

Re: Placing php code in a sidebar
Posted: Mon May 01, 2006 2:44 pm
by garvinhicking
Hi!
The javascript in the sidebar should basically work well; what did you enter? And did you disable the "Apply Markup Transformations" option for that nugget? And if you use the WYSIWYG editor, you need to put it into HTML source mode to enter javascript.
Having said this, PHP in the sidebar is also very easy, you can just create your own plugin. It's as easy as this:
Code: Select all
<?php # $Id: serendipity_plugin_authors.php,v 1.11 2005/08/01 18:20:06 garvinhicking Exp $
@define('PHPADSNEW_TITLE', 'phpAdsNew');
class serendipity_plugin_phpadsnew extends serendipity_plugin
{
var $title = PHPADSNEW_TITLE;
function introspect(&$propbag)
{
$propbag->add('name', PHPADSNEW_TITLE);
$propbag->add('description', PHPADSNEW_TITLE);
$propbag->add('stackable', true);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
$propbag->add('configuration', array('title'));
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE);
$propbag->add('default', PHPADSNEW_TITLE);
break;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
include '/your/path/to/the/phpadsnew/snippet/code.php';
}
}
(BTW, the minimum code for a plugin would be this:
Code: Select all
<?php
class serendipity_plugin_phpadsnew extends serendipity_plugin
{
function introspect(&$propbag) {
$propbag->add('name', 'phpAdsNew');
}
function generate_content(&$title) {
include '/your/path/to/the/phpadsnew/snippet/code.php';
}
}
Now, tell me, isn't serendipity's plugin API great?
Regards,
Garvin
Thanks
Posted: Tue May 02, 2006 5:25 am
by MichaelParent
Thanks so much Garvin,
You are wonderfully helpful

Thanks to you, I've tho the java script working, however, I've not been able to get the plugin you've given me to work. I've copied and pasted it into notepad. Then saved it off as a php named phpadnew.php. I then created a new folder called serendipity_plugin_phpadnew in the plugins folder of serendipity and put the php file in there. When I check to see if the new plugin is availible, serendipity says error:phpadnew
I'm guessing I'm missing something simple, but I am extreemely inexperienced with this sort of thing. any suggestions?
thanks again for all your help.
Re: Thanks
Posted: Tue May 02, 2006 9:08 am
by garvinhicking
Hi!
I'm sorry I didn't give you more verbose instructions. You need to save that code I pasted as "plugins/serendipity_event_phpadsnew/serendipity_event_phpadsnews.php". The filename must be the same as the php classname.

)
Best regards,
Garvin
Got it working! :)
Posted: Tue May 02, 2006 5:44 pm
by MichaelParent
Thanks again Garvin
It worked once I made the folder and the php file name the same exact name as you had made the class name in the php text itself. ( serendipity_plugin_phpadsnew ). Once I did that, and once I put the full html adress of the php file that phpadnews had generated in the code you had originally supplied, it worked perfectly.
Just to clarify, though, for else following this thread, it was a plugin and not an EVENT as Garvin had typed out. I tried that first and it didn't work, then realised he had just mistakenly typed out the words event instead of plugin. Once I just copied the php class name as he instructed, it worked perfectly
Thanks again Garvin!
Re: Got it working! :)
Posted: Tue May 02, 2006 6:04 pm
by garvinhicking
Great to hear that! And sorry once again for my mistake
Best regards,
Garvin
Now I need to center the Banner ;)
Posted: Sun May 14, 2006 7:15 am
by MichaelParent
Hello again....hopefully people will see the new question on this old post
I've got the banner rotation working, as mentioned before, thanks to Garvin.
Now my situation is this: I'm rotating between banners that are all 125 pixels in height, but are slightly different widths. The banner that is 140 pixels wide looks great in its place in the sidebar, because it takes up the whole width. When a thinner banner is displayed (the 125px wide one), it looks a little unprofessional as its left justified instead of centered horizontally.
Anyone have any idea how i can fix this? Do I ad something to my stylesheet, the php code generated by the adserver program, or both?
thanks
you can see the actual situation here :
http://www.bestsharewaregames.com/serendipity
Re: Now I need to center the Banner ;)
Posted: Sun May 14, 2006 3:05 pm
by garvinhicking
Hi!
You will need to put a CSS code that applies to the elements in your container and put a "text-align: center; margin: 0px auto 0px auto" in that directive:
Code: Select all
.container_serendipity_plugin_phpadsnew .serendipitySideBarContent {
text-align: center;
margin: 0px auto 0px auto;
}
Regards,
Garvin
You're like a serendipity superhero Garvin!
Posted: Sun May 14, 2006 7:21 pm
by MichaelParent
With your code I was able to center the sidebar banners and the leaderboard banner at the bottom of the page. Thanks so much! (Yet again!)