WordPress.org

Ready to get started?Download WordPress

Forums

How to Add Facebook Share to Index.php (6 posts)

  1. evilbeet
    Member
    Posted 4 years ago #

    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="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></strong>
    
    <br />
    </div>
    
    <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>
    
    </div>
    <?php endwhile; ?>

    The bolded section is what should be the FB share code. You can check out the problem right now -- the site is http://evilbeetgossip.com. Thanks!

  2. xdigitaldollx
    Member
    Posted 4 years ago #

    Im having the same problem for both Facebook Share & TweetMeMe.. Some help would be awesome!

  3. evilbeet
    Member
    Posted 4 years ago #

    Bump? Is this just not possible?

  4. apocalypse7
    Member
    Posted 4 years ago #

    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

    -A7

  5. sdcr
    Member
    Posted 4 years ago #

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

    share_url="<?php the_permalink();?>" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>">Share
    <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

    That's it!

  6. tisthammer
    Member
    Posted 4 years ago #

    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>
    					</h1>
    
    					<?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(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic