Support » Themes and Templates » How to Add Facebook Share to Index.php

  • I’m trying to add Facebook Share buttons on my index.php, so that they show up after every article on the homepage, but for some reason the button always links back to the main page rather than the permalink for the specific blog post. Here’s what my code for the loop looks like right now:

    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    				<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
    <div class="entry">
    <?php the_content('Jump in &raquo;'); ?>
    <small><?php the_time('F jS, Y') ?>  by <?php the_author_posts_link() ?> <?php if(function_exists('the_views')) { the_views(); } ?> </small>
    <strong><a name="fb_share" type="button_count" href="<?php the_permalink();?>&t=<?php the_title(); ?>">Share</a><script src="" type="text/javascript"></script></strong>
    <br />
    <p class="postmetadata">Read all about <?php the_category(', ') ?>  <?php the_tags( ", ", ", "); ?>  | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    <?php endwhile; ?>

    The bolded section is what should be the FB share code. You can check out the problem right now — the site is Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Im having the same problem for both Facebook Share & TweetMeMe.. Some help would be awesome!

    Bump? Is this just not possible?

    Well I think with the new F8 summit they killed Facebook Connect, not sure if Facebook Share was as well. It think they switched a new “Like” button instead of sharing. Regardless, since its the new standard Facebook is planning on implementing might as well hack @ it. This might help you out with that.
    How to – Add Facebook LIKE button to WordPress Posts




    It is possible, you can do it by adding a tag “share_url=”

    share_url=”<?php the_permalink();?>” href=”<?php the_permalink();?>&t=<?php the_title(); ?>”>Share
    <script src=”” type=”text/javascript”></script>

    That’s it!

    This a file called Single Post (single.php).
    Is this where I’m supposed to insert the share-code? Please show me where:) The last time I altered a php document it all went to hell.

    Thank you.

    <?php get_header(); ?>
    <div class="content">
    <div id="primary-wrapper">
    	<div id="primary">
    		<div id="notices"></div>
    		<a name="startcontent" id="startcontent"></a>
    		<div id="current-content" class="hfeed">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<?php k2_navigation('nav-above'); ?> 
    			<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    				<div class="entry-head">
    					<h1 class="entry-title">
    						<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php k2_permalink_title(); ?>"><?php the_title(); ?></a>
    					<?php /* Edit Link */ edit_post_link( __('Edit','k2_domain'), '<span class="entry-edit">', '</span>' ); ?>
    					<div class="entry-meta">
    						<?php k2_entry_meta(1); ?>
    					</div> <!-- .entry-meta -->
    					<?php /* K2 Hook */ do_action('template_entry_head'); ?>
    				</div><!-- .entry-head -->
    				<div class="entry-content">
    					<?php if ( function_exists('has_post_thumbnail') and has_post_thumbnail() ): ?>
    						<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'medium', array( 'class' => 'alignleft' ) ); ?></a>
    					<?php endif; ?>
    					<?php the_content( sprintf( __('Continue reading \'%s\'', 'k2_domain'), the_title('', '', false) ) ); ?>
    				</div><!-- .entry-content -->
    				<div class="entry-foot">
    					<?php wp_link_pages( array('before' => '<div class="entry-pages"><span>' . __('Pages:','k2_domain') . '</span>', 'after' => '</div>' ) ); ?>
    					<div class="entry-meta">
    						<?php k2_entry_meta(2); ?>
    					</div><!-- .entry-meta -->
    					<?php /* K2 Hook */ do_action('template_entry_foot'); ?>
    				</div><!-- .entry-foot -->
    			</div><!-- #post-ID -->
    			<div class="comments">
    				<?php comments_template(); ?>
    			</div><!-- .comments -->
    			<?php k2_navigation('nav-below'); ?> 
    		<?php endwhile; else: define('K2_NOT_FOUND', true); ?>
    			<?php locate_template( array('blocks/k2-404.php'), true ); ?>
    		<?php endif; ?>
    		</div><!-- #current-content -->
    		<div id="dynamic-content"></div>
    	</div><!-- #primary -->
    </div><!-- #primary-wrapper -->
    <?php if ( ! get_post_custom_values('sidebarless') ) get_sidebar(); ?>
    </div><!-- .content -->
    <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to Add Facebook Share to Index.php’ is closed to new replies.