phpwordpressmillennial-media

Millennial Media PHP Setup ( Code Integration )


I know this going to be very easy question for people with good PHP knowledge.

I have a WordPress website self hosted. I designed it for mobile devices and I would like to install Millennial Media advertisements in it. Millennial Media does not really provide detailed instructions and web resources strangely are not available!

I have knowledge in HTML,CSS and JavaScript but very poor in PHP :( . any way I can do some changes PHP to achieve what I want, but I can't write them from zero and integrate them by my self.

Ok long story short This the code provided by Millennial Media:

<?php 
/*--------------------------------------------------------------*/ 
/* Millennial Media PHP Ad Coding, v.7.4.20                     */ 
/* Copyright Millennial Media, Inc. 2006                        */ 
/*                                                              */ 
/* The following code requires PHP >= 4.3.0 and                 */ 
/* allow_url_fopen 1 set in php.ini file.                       */ 
/*                                                              */ 
/* NOTE:                                                        */ 
/* It is recommended that you lower the default_socket_timeout  */ 
/* value in the php.ini file to 5 seconds.                      */ 
/* This will prevent network connectivity from affecting        */ 
/* page loading.                                                */ 
/*--------------------------------------------------------------*/ 

/*------- Publisher Specific Section -------*/ 
$mm_placementid = 123456; 
$mm_adserver = "ads.mp.mydas.mobi"; 

/* The default response will be echo'd on the page     */
/* if no Ad is returned, so any valid WML/XHTML string */
/* is acceptable.                                      */
$mm_default_response = "";

/*------------------------------------------*/

/*----------- BEGIN AD INITIALIZATION ----------*/
/*----- PLEASE DO NOT EDIT BELOW THIS LINE -----*/
$mm_id = "NONE";
$mm_ua = "NONE";
@$mm_ip = $_SERVER['REMOTE_ADDR'];

if (isset($_SERVER['HTTP_USER_AGENT'] )){
     $mm_ua = $_SERVER['HTTP_USER_AGENT'];
}

if (isset($_SERVER['HTTP_X_UP_SUBNO'])) {
          $mm_id = $_SERVER['HTTP_X_UP_SUBNO'];
} elseif (isset($_SERVER['HTTP_XID'])) {
          $mm_id = $_SERVER['HTTP_XID'];
} elseif (isset($_SERVER['HTTP_CLIENTID'])) {
          $mm_id = $_SERVER['HTTP_CLIENTID'];
} else {
          $mm_id = $_SERVER['REMOTE_ADDR'];
}

$mm_url = "http://$mm_adserver/getAd.php5?apid=$mm_placementid&auid="
          . urlencode($mm_id) . "&uip=" . urlencode($mm_ip) . "&ua="
          . urlencode($mm_ua);
/*------------ END AD INITIALIZATION -----------*/
?>

<?php
/* Place this code block where you want the ad to appear */
/*------- Reusable Ad Call -------*/
@$mm_response = file_get_contents($mm_url);
echo $mm_response != FALSE ? $mm_response : $mm_default_response;
/*--------- End Ad Call ----------*/
?>

I want the Advertisement to appear in the footer area ( I will edit the footer.php in twenty eleven theme ) but I want to know where shall I put these pieces of codes in wordpress files or shall I create a new ones and what to name them?

would some please help me with this issue and provide me with the file's names that required to be edited and how would they look like in the end ?

Thanks


Solution

  • Anywhere in your page, where you want the ad to appear, let's say inside a <div>, use:

    <div>
       <?php include('thatfiletheysentyou.php'); ?>
    </div>
    

    This will make output of that file appear where include is.

    EDIT: Complete rewrite:

    This is content of footer.php. I just installed wordpress for you, took 3 minutes. I edited footer.php including <?php include('ads.php'); ?> (see below), which appeared in footer, as expected

    <?php
    /**
     * The template for displaying the footer.
     *
     * Contains the closing of the id=main div and all content after
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    ?>
    
        </div><!-- #main -->
    
    
        <footer id="colophon" role="contentinfo">
    
                <?php
                    /* A sidebar in the footer? Yep. You can can customize
                     * your footer with three columns of widgets.
                     */
                    if ( ! is_404() )
                        get_sidebar( 'footer' );
            ?>
    
            <div id="site-generator">
            <div>
             <?php include('ads.php'); ?>
            </div>
        <?php do_action( 'twentyeleven_credits' ); ?>
        <a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentyeleven' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentyeleven' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentyeleven' ), 'WordPress' ); ?></a>
            </div>
    </footer><!-- #colophon -->
    </div><!-- #page -->
    
    <?php wp_footer(); ?>
    
    </body>
    </html>
    

    Now if you got a file from the ad company, change ads.php above to this file name. If you got a code pasted in (i don't know, an e-mail, website) - create a file ads.php and paste whatever you got from them. Place that file in twentyeleven subfolder. My file looks like this:

    <?php
      echo 'HEHEHE!';
      //instead of this just paste your code here
    ?>
    

    and on the page it is like so: 1 http://www.spzozwolsztyn.internetdsl.pl/wpress.jpg

    If you got tired of them remove include line from footer.php.