Title: Writing a plugin
Last modified: August 19, 2016

---

# Writing a plugin

 *  [Mobster](https://wordpress.org/support/users/mobster/)
 * (@mobster)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/writing-a-plugin/)
 * Here’s another guy trying to learn how to write a plugin. I am VERY new to writing
   a plugins and this is the only method in which I can get my function to work.
 * In the world of plugins, is it ok to write a function like this.
 *     ```
       function my_function()
       {
          ?>  
   
       <div id="box">
   
       <div id="myLoop">
       <?php query_posts('showposts=5');?>
                 <?php while (have_posts()) : the_post(); ?>
                 <div>
                           <div class="title"><a href="<?php the_permalink() ?>">
   
                                     </a></div>
                           <a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>">
                           <h3><strong><?php the_title(); ?></strong></h3>
                           </a>
                         <?php the_excerpt(); ?>
                 </div>
                 <?php endwhile; ?>
                 //Reset Query
       <?php wp_reset_query(); ?>
   
       </div>
       </div>
       <?php
        }
        ?>
       ```
   
 * And then include the function on a page with:
 *     ```
       <?php
       if (function_exists("my_function")) {
         my_function();
       }
       ?>
       ```
   
 * Should I code this differently when working with pluin API?
 * Thanks for any help.

The topic ‘Writing a plugin’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [Mobster](https://wordpress.org/support/users/mobster/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/writing-a-plugin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
