Title: Post Loop for WordPress 2
Last modified: August 18, 2016

---

# Post Loop for WordPress 2

 *  [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/)
 * Can anyone give me a pointer to the file in wordpress 2 where I can find the 
   Post loop?
 * I am using Semiologic theme and the index file points to:
 * <?php
    require_once(TEMPLATEPATH . ‘/header.php’);
 * the_posts();
 * require_once(TEMPLATEPATH . ‘/footer.php’);
    ?>
 * But I’m not sure where to locate the “the_posts();” loop in a file, so that I
   can add some PHP to the end of each post.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/post-loop-for-wordpress-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/post-loop-for-wordpress-2/page/2/?output_format=md)

 *  [Denis de Bernardy](https://wordpress.org/support/users/denis-de-bernardy/)
 * (@denis-de-bernardy)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-371882)
 * wp-content/plugins/sem-theme/
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-371905)
 * Thanks Denis,
 * What I am trying to do is add the social bookmarking plugin to the end of each
   post – before permalink.
 * Social Bookmark Links WordPress Plugin
    [http://www.twistermc.com](http://www.twistermc.com)
 * Basically one line of code:
    <? social_bookmark(); ?>
 * I tried to add it in the sem-theme-posts.php but had to reinstall semiologic 
   because it crashed the site.
 * Any suggestions where I could add it?
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-371909)
 * One way is to create a tiny little plugin to do it.
 * Save the following code as show_sb.php, upload to your plugins folder, and enable
   it. It should do the trick without having to modify the existing plugin, or any
   WP files.
 * `
    <?php /* Plugin Name: Show Social Bookmarks Below Posts Plugin URI: http://
   www.whatever.com Description: Whatever Author: Whoever Version: 1.0 Author URI:
   http://www.whatever.com */
 * function call_sb($content) {
    if (is_single()) return $content . social_bookmark();
   else return $content; }
 * add_filter('the_content', 'call_sb');
    ?>
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-371918)
 * Almost what I was looking for.
 * -It works on a post by post basis but not on the home page where all posts are
   indexed
    -It before the post not after
 * Thanks for trying.
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-371924)
 * Well I just wrote that, so I can easily change it.. 🙂
 * If you meant that you want it to work on the homepage too, change this line:
 * `if (is_single())`
 * To this:
 * `if (is_single() || is_home())`
 * And that plugin _should_ be outputting the social_bookmark code at the bottom
   of the post.
 * The problem is that the social_bookmark function is echoing the output, instead
   of returning it. This makes it hard to position if it is called from a plugin.
 * This can be easily fixed, but the social bookmark plugin needs a small modification.
 * If you give me the link to the copy you are using, I can fix it, and add in the‘
   show at the bottom of every post’ feature too, so you do not have to use that
   little plugin to do it.
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372069)
 * Thanks for the offer I placed the code here:
 * [http://www.teachinghacks.com/files/social-bookmark.txt](http://www.teachinghacks.com/files/social-bookmark.txt)
 * I really appreciate it.
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372093)
 * No problem. I will fix it up when I get home today, and post back. (about two
   hours from now hopefully).
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372111)
 * Ok. I am through:
 * [http://www.dagondesign.com/files/social-bookmark.txt](http://www.dagondesign.com/files/social-bookmark.txt)
 * Here is what I did:
 * First I renamed the social_bookmark function to social_bookmark_generate, and
   set it to return the data instead of just echoing it.
 * Now to keep things working with your current stuff, I then created a function
   called social_bookmark which runs the generate function, but then echos the output.
   Just like the function did originally. This way any ‘standard style’ calls to
   the function will work like they did before.
 * Lastly, I set it up so that at the end of each post (on the index or post page),
   it will call the generate function, and append the output to the end of the post.
 * So just enable this version and you will have the stuff at the bottom of each
   post, as well as the ability to use it wherever else you want, with the standard
   method.
 * 🙂
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372123)
 * This worked awesome! Thanks very much for your help.
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372124)
 * Very cool 🙂 No problem, glad it worked.
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372132)
 * Just a question for later modifications. If I want to add further functions on
   to the end of posts how can I do it.
    Later on I am going to want to add the 
   folowing, to the end of the posts. ————- if ( is_single() or is_page() ) { if(
   function_exists(‘get_the_post_keywords’) and function_exists(‘related_posts_jerome_keywords’)){
   $relatedposts = related_posts_jerome_keywords(); if ($relatedposts === false){//
   echo ‘No related posts’; } else { echo ‘<div class=”related-posts”> <h3>Related
   posts:</h3>
    - ‘ . $relatedposts . ‘
 * </div> <!– [related-posts] –>’;
    } } }
 * Can I add this to the social-bookmark.php or is it better to do something seperate?
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372149)
 * I would make it into it’s own plugin file. Try this:
 * `<?php
    /* Plugin Name: Give it a name here Plugin URI: whatever.com Description:
   Whatever Author: Whoever Version: 1.0 Author URI: whatever.com */
 * function f_get_related($content) {
 * $t_output = "";
 * if (is_single() || is_page()) {
 * if (function_exists('get_the_post_keywords') && function_exists('related_posts_jerome_keywords')){
 * $relatedposts = related_posts_jerome_keywords();
 * if ($relatedposts === false) {
 * // $t_output .= 'No related posts';
 * } else {
 * $t_output .= '<div class="related-posts"><h3>Related posts:</h3>' . $relatedposts.'
   </div> <!-- [related-posts] -->';
 * }
 * }
 * return $content . $t_output;
 * }
 * add_filter('the_content', 'f_get_related');
 * ?>
 * Notice that instead of using ‘echo’ it puts everything into a temp string.. then
   it gets added to the end of the content. That way it always goes where it should.
   Echo can be tricky to use in plugins, because they do not always execute where
   the output needs to go 🙂
 * Be sure of course that you do not have any extra lines or spaces before or after
   the code when you save it to a file.
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372234)
 * Thanks very much.
 * I did try this plugin but it didn’t work very well. I ended up with a blank screen.
   I just deleted the plugin and the site came back up.
 *  [aleister](https://wordpress.org/support/users/aleister/)
 * (@aleister)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372235)
 * I just grabbed that code you posted and stuck it in a basic template without 
   really testing it, so who knows 🙂
 *  Thread Starter [qdsouza](https://wordpress.org/support/users/qdsouza/)
 * (@qdsouza)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/#post-372238)
 * That’s okay. Thanks very much for your help. I really do appreciate it.
 * Just one quick question – how did you learn so much about wp plugins? Did you
   use the tutorials about developing plugins in the wordpress support site or did
   you just keep playing around with the code?

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/post-loop-for-wordpress-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/post-loop-for-wordpress-2/page/2/?output_format=md)

The topic ‘Post Loop for WordPress 2’ is closed to new replies.

 * 16 replies
 * 3 participants
 * Last reply from: [aleister](https://wordpress.org/support/users/aleister/)
 * Last activity: [20 years, 1 month ago](https://wordpress.org/support/topic/post-loop-for-wordpress-2/page/2/#post-372239)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
