How to integrate WP Plugins with themes

Discussion in 'WordPress' started by Nandamuri, Jun 19, 2009.

  1. #1
    Could somebody tell the procedure to integrate wordpress plugins with the theme.

    I started designing some wordpress themes. I want some functionalities of some plugins. But, I do not want to ask theme downloaders to, download and install certain plugins, for the complete functionality of theme.

    I want to know how could we do that
     
    Nandamuri, Jun 19, 2009 IP
  2. fish

    fish Well-Known Member

    Messages:
    450
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Sometimes it's possible to copy the plugin code in the functions.php file of the theme. I've seen some theme authors bundle plugins with their themes as well. This might make more sense depending on how complicated the plugin is.

    When integrating the plugin code in your template file, make sure to use code like this to check if the plugin is active.

    <?php if (function_exists('function_name')) { ...plugin code here... } ?>
    Code (markup):
    Else there will probably be an error like this that will cause your theme to break.
     
    fish, Jun 20, 2009 IP
  3. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Basically, you rip out the function code and integrate it into the pages where it is needed. The hooks at the bottom and the comments at the top are not required.

    It's only practical if the plugin is very small though. Most plugins have too much code to be integrated into a theme.
     
    Cash Nebula, Jun 20, 2009 IP
  4. Nandamuri

    Nandamuri Peon

    Messages:
    665
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I want to integrate recent comments, recent posts plugin with my wordpress theme.

    Are there any functions which do my requirement with out any PLUGINS Eetc
     
    Nandamuri, Jun 20, 2009 IP
  5. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is how magazine themes show recent comments and posts.

    For recent posts, they use this code:
    
    <div id="recent-posts">
    <h4>Recent Posts</h4>
    <p></p>
      	<?php query_posts('showposts=5'); ?>
    	<ul>
    	<?php while (have_posts()) : the_post(); ?>
    	<li>
    	<strong><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); ?> <?php the_title(); ?>"><?php the_title(); ?></a></strong><br />
    	<small><?php the_time('m-d-Y') ?></small>
    	</li>
    	<?php endwhile;?>
    	</ul>
    </div>
    
    Code (markup):
    For recent comments, they use Simple Recent Comments with this code:
    
      <div class="recent-comments">
        <?php include (TEMPLATEPATH . '/simple_recent_comments.php'); /* recent comments plugin by: www.g-loaded.eu */?>
    	<?php if (function_exists('src_simple_recent_comments')) { src_simple_recent_comments(5, 60, '<h4>Recent Comments</h4>', ''); } ?>
      </div>
    
    Code (markup):
    I just copied them from free themes so they should work ;)
     
    Cash Nebula, Jun 20, 2009 IP
  6. fish

    fish Well-Known Member

    Messages:
    450
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Another easy way to have a list of recent posts (without using query_posts) would be something like the following:

    <h3>Recent Posts</h3>
    <ul>
    <?php wp_get_archives('type=postbypost&limit=5'); ?>
    </ul>
    Code (markup):
    Change the "limit" to the number of recent posts you want listed.
     
    fish, Jun 20, 2009 IP
  7. Nandamuri

    Nandamuri Peon

    Messages:
    665
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you very much. I tried to correct both of them.

    I was successful in getting RECENT POSTS and RECENT COMMENTS. Once again many thank for the help
     
    Nandamuri, Jun 20, 2009 IP
  8. Nandamuri

    Nandamuri Peon

    Messages:
    665
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have got a new problem with my themes..

    Please help me in this also
     
    Nandamuri, Jun 20, 2009 IP
  9. Nandamuri

    Nandamuri Peon

    Messages:
    665
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Nandamuri, Jun 20, 2009 IP
  10. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #10
    No trouble :)

    Sure, wp_get_archives is much simpler, but you don't have as much control over the list.

    I think I have solved your other problem too.
     
    Cash Nebula, Jun 20, 2009 IP