• Hi,
    I am a starter and would be happy to get some help in creating a plugin.

    What I want to achieve is, display a Flash Movie (example: myMovie.swf) from a “plugins/myPlugin” folder by inserting a PHP code in the template PHP code.

    Looks simple but cant get to it 🙁

    Here is my existing code:


    <?php

    /*
    Plugin Name:
    Plugin URI:
    Description:
    Author:
    Version:
    Author URI:
    */

    add_action('the_content', 'my_function');

    function my_function()
    {

    $output = "<object type=\"application/x-shockwave-flash\" data=\"$filename\" width=\"600\" height=\"212\"><param name=\"movie\" value=\"$filename\" /></object>";
    return $output;
    }
    ?>

    After activating the plugin, I added this code to the index.php (header):


    <?php get_header(); ?>

    <?php if (function_exists('my_function')) : ?>

    <?php my_function(); ?>

    <?php endif; ?>

    When I use this code, the flash movie gets embeded in every post.

    Any help??

Viewing 8 replies - 1 through 8 (of 8 total)
  • If your flash is showing in every post, you propably added the code within the post loop. Add it in the sidebar.php file and see if that works.

    Thread Starter ssdesign

    (@ssdesign)

    I have placed the code right after the get_header() function as shown above.

    If I view the source of the resulting page, this is what I find:

    Immediately after the line:
    <small>October 5th, 2005 <!– by Administrator –></small>

    I get my flash code:

    <div class=”entry”>
    <object type=”application/x-shockwave-flash” data=”” width=”600″ height=”212″><param name=”movie” value=”” /></object>
    </div>

    The code gets wrapped inside a DIV with class ENTRY.

    If you look at my plugin code, I hve not specified any DIV, this ENTRY DIV gets added automatically.

    Do I need to change this line in my plugin???

    add_action(‘the_content’, ‘my_function’);

    Could this be the problem?

    This is culprit: add_action('the_content', 'my_function');

    You’ve hooked it to the content. So everytime the content is displayed, your flash movie is shown.

    What is it exactly that you are trying to achieve? At what times, and where do you want the movie to be shown? And at what times do you NOT want it shown?

    -tg

    ahh yeah. techgnome is right.

    Thread Starter ssdesign

    (@ssdesign)

    Ok so let me describe what i am trying to do.

    With this plugin, i want to add a carton strip just below the header. It will be a ‘Daily Dilbert’ cartoon updated daily using the dilbert RSS feed.

    So in effect, i has to appear only once. Just before the first blog entry is displayed.

    This is the reason why i was copying the code immediately after the head tag like this:

    <?php get_header(); ?>

    <?php if (function_exists(‘my_function’)) : ?>
    <?php my_function(); ?>
    <?php endif; ?>

    Can you guide me to the right way?
    Also this plugin will be made public once i get it working.

    Thanks.

    if you >explicitly< have a call to my_function within index.php, you don’t need to have add_action(‘the_content’, ‘my_function’)… the index.php call does everything you need. get rid of the add_action call, and it should work fine.

    -d

    Thread Starter ssdesign

    (@ssdesign)

    thanks david, i will give it a try and post the development soon.

    Thread Starter ssdesign

    (@ssdesign)

    hi David, It solved my rpoblem.

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Help creating plugin’ is closed to new replies.