custom php function to call in header - php

I have a Wordpress website. I am asking for help as I am not good with codes, but know a bit about the flow of functions and all.
I want to add a new PHP function that will be defined in a separate file. The function to be defined is required to serve a 728x90 banner ad on top of the header area of the site (so I guess the php function will also have CSS styling to align the ad in the center). I don't know what I am saying will be possible the way I am saying.
Alternatively, there might be a way to call a js function defined in separate file, then called in the php header to serve the banner (again center-aligned).
I am seeking help here as Stackoverflow also helped me solve problems previously.
Is there anyone who can help me get this thing done?

Once you have your PHP handler written in a separate file call it using require_once like this:
<?php
require_once('myfile.php');
// Wordpress Stuff
?>

I guess PHP have no relation with CSS/styling, you can do it with Javascript.
like this or using JQuery

Related

Calling PHP from Smarty template

I am trying to integrate an ad package into my Smarty based site. I have been given the following PHP code that I need to add to my footer file. But due to it being Smarty I need to add the code instead to my php file so that it can be called/included in my Smarty template file. This was the code that I was given and that I need to include:
<?php if(function_exists('ad_footer')) ad_footer(); ?>
But in the php file I am not sure how to achieve this - I have got this example and wanted to know if it looked correct??
if(function_exists('ad_footer')) {
ob_start();
ad_footer();
$smarty->assign('ad_footer', ob_get_clean());
}
Does the above look the right way to do it?
Thanks in advance
I went ahead and created a test page to see if the above worked and it did so will stick with this code.

How can a class be added to a div via php?

I have this h tag below,
<h3 id="reply-title">
& I needed to add a class to it remotely.
(This h3 tag is located in comment-template.php. (line 1554) of WordPress core file in case you are wondering why I can't just hard code the class to it.)
I've done this with one line jQuery (add class on .load) but now, I am concerned since if javascript is turned off, the class won't be added.
I have very little knowledge of php and I am wondering if this can be done in php. I've done some research on google & I couldn't find any reference.
Any php expert who can provide some insight?
This is in general a bad practice, but you can do that like this:
echo "<script>$('#reply-title').addClass('class')</script>";
But I repeat: This is a bad practice. The Javascript must be in .js files, and the PHP in .php files.
However, if the Javascript is disabled, I think you can't do what you want.
Hope this helps.

PHP + Smarty: Parse PHP+HTML into a String?

I am using PHP in combination with Smarty Templates to generate pages serverside. Currently, I am loading a page as follows:
$smarty->assign('app', file_get_contents("some_content.php"));
Where some content contains HTML with PHP tags and code inside those tags.
I would like the PHP content inside this file within the current scope (That of the script reading the file), so that a particular function I've defined is available. How would I go about doing so? All the information I can find is regarding the eval(...) function, which doesn't seem to be able to cope with the HTML/PHP mixture: would I need to perform a find/eval/replace operation to achieve the desired result, or is there a more elegant way of doing this?
From my opinion, this short snippet of the code you posted shows that something is generally wrong there :)
But nevertheless you can achieve whatever you are trying to achieve by doing the following:
ob_start();
include("some_content.php");
$result = ob_get_clean();
$smarty->assign('app', $result);
Ich, I'm such a dummkopf. There is an answer right on the PHP manual for eval, right under my nose. Here is the answer I neglected to notice.
You can use {literal}...{/literal} smarty tags to display any content in smarty templates as is. It used to transfer java scripts and other specific content.

Drupal 6 Rules Execute custom php output not in html body

I'm using drupal-6.22, rules-6.x-1.4, and some modules.
With the help of rules module, I've set a triggered rule, when the condition happens, it execute custom php code.
The custom PHP print some html like this:
<?php echo '<div><span>whatever</span></div>'; ?>
BUT, the html just appears before the !DOCTYPE html tag, is there any method to place the code wherever I want?
(e.g. <div id="header">HERE!</div>)
I think in this case JS is in need, so I use drupal_add_js($output,'inline'), and called an outside function to place the html, still nothing happens.
I think there must be some method to let PHP insert the output into the current DOM tree, is there any known function or variables for this?
Please help, thanks!!
drupal_set_message() seems to be the right thing for you.

Getting facebox to work in the qcodo/qcube php framework

I am using a framework called qcodo (which forked as qcubed) and is a PHP framework.
I want to do a very simple popup using the Facebox jquery plugin.
When someone clicks on the link and shown below in line 47.
Here is the file: http://github.com/allyforce/AF-upload/blob/master/Templates/profile_activity.tpl.php
<a href="complete_profile_popup.php?allyId=<?= $this->objAllyUser->Id?>" rel="facebox" title="Complete Profile" >Invite as Ally</a><br />
The Facebook installation worked fine, tested it just opening plain html and php files.
I just want to be able to render a working page within the Facebox pop-up.
But the current error is that it cannot recognize the method, even though it appears it has been defined.
UPDATE: Per one suggestion, used iFrame, but still getting nothing:
You should print the error you get. I will try to guess: have you declared your method as public? In the template you can access only public properties and methods. This is a very common mistake.
This issue/topic is being discussed in depth at http://www.qcodo.com/forums/forum.php/3/4007/

Categories