Recent Topics

1 Jan 07, 2006 06:30    

I tried searching the forums to no avail...

Could someone please tell me how to incorporate PHP into my posts? This is what I want to add:

<?
include("../pk/rating.php");
print pkrating::get_required_hidden_html();
?>

< ? 
$rating_red = new pkrating('rating_red');
print $rating_red->get_booth_html();
?>


It just shows up as text in my post - http://tastyrobot.com/b2/index.php/2005/12/30/test

Many thanks :D

2 Jan 07, 2006 13:09

AFAIK it can't be done. Not *IN* the post anyway because the post content is effectively considered HTML and simply stuck in where it belongs as b2evolution builds a page. What you can do, if you want the same code associated with every post, is to put it in the post loop in your skin's _main.php file.

3 Jan 08, 2006 18:42

The only problem with putting the code in _main.php is that the same rating poll would appear for every single post, but I want each post to have a unique rating poll. The part of the code that says "red"

<?
$rating_red = new pkrating('rating_red');
print $rating_red->get_booth_html();
?>


is actually the name of the poll, which has to change for each post. It'd be a pain in the ass, but I could create a Javascript to include on each post, right? Or would that not work? I have HTML Checker off but still, I'm not sure if that would fly. Any other ideas?

PS - Here's an example of where the rating poll DOES work (not w/in b2e): http://tastyrobot.com/pk/example.php

4 Jan 08, 2006 20:07

That's a bummer. Javascript won't do it because Javascript is processed by the visitor's browser. The PHP code would still be fed as text via the blog engine. Unless you tweaked it to be ENTIRELY javascript...

Alternatively, if you're into hacking, you can tweak the PHP for the poll to include the post_ID. The field might be "ID" and not "post_ID" but if you get the idea then the details shouldn't be too hard to work out. After that you need your poll software to respond to that particular detail and add votes to the correct post's 'tally'. I'm guessing the poll software will allow multiple polls?

Either way it's a hack, so the method you're most comfortable with be the best. Bottom line is that PHP is processed by the server, but not PHP inside post content. Thus you need either pure Javascript or a PHP method to include the post_ID with the poll as part of the post loop in your _main.php.

I think! I'm sometimes completely wrong, but that's never stopped me from thinking ;)

5 Jan 08, 2006 20:17

Take a look at the bbcode plugin ;)

¥

6 Jan 08, 2006 22:28

Thanks for the tips...

EdB - The script does allow for multiple polls, but I don't know enough about PHP to get that deep into hacking. Thanks though. :D

Yabba - I'll look through the forums. I've used BBCode a couple times but not extensively so I'll research and let ya know how it works out.

Thanks again guys :)

7 Jan 11, 2006 04:05

Yabba - I couldn't find anything about BBCode that would help me. :(

EdB - I finally realized what you meant about hacking the PHP (I'm a little slow ;) ) so this is what I came up with:

<?php
include("../pk/rating.php");
print pkrating::get_required_hidden_html();
?>

<?php
$rating_$post_ID = new pkrating('rating_$post_ID');
print $rating_$post_ID->get_booth_html();
?>


This just gives me an error that says "Parse error: parse error, unexpected T_VARIABLE in /home/tastyro/public_html/b2/skins/custom/_main.php on line 269". (269 is the line that begins "$rating_".) I'm assuming "$post_ID" isn't formatted the right way for the script. Any ideas? (I've also tried "$ID", "post_ID" and "ID" to no avail.)

Also, I'm not exactly sure where to insert the script... does it matter? And just for clarification - I should be inserting this into the _main.php of my skin, not any other _main.php, right? Sorry I'm such a n00b at this!

8 Jan 11, 2006 09:41

I was a tad cryptic huh? :P

You can use the bbcode plugin to insert any code you want to into a post "fairly" easily, with a tad or lateral thinking.

Your main problem with your current code is the extra $'s, if you remove them you should be good to go

<?php
$rating_post_ID = new pkrating('rating_'.$Item->ID);
print $rating_post_ID->get_booth_html();
?>

It does go into the _main.php (of the skin you're using) and probably just after the line that reads $Item->content();

;)

¥

9 Jan 12, 2006 04:27

You guys are the bees knees!

So here's what I had to do:

    I stuck this in the <head>:
    <?php
    include("../pk/rating.php");
    print pkrating::get_required_hidden_html();
    ?>
    I had it in the <body> originally, but I got a fatal error for calling pkrating twice.[/list:u]
      Then I put this where I wanted it in the <body>:
      <?php
      $rating_post_ID = new pkrating('rating_'.$Item->ID);
      print $rating_post_ID->get_booth_html();
      ?>
      [/list:u] Thanks so much! You guys are teh roxxorz! :D


Form is loading...