WordPress.org

Support

Support » How-To and Troubleshooting » [Plugin: Sociable] Display for first item only in index.php

[Plugin: Sociable] Display for first item only in index.php

  • Here’s another one that I suspect is a WordPress/php/if-else question:

    I pasted the Sociable script beneath the_content in index.php, and I’m displaying full text for the first entry only, with excerpts for everything that follows. (Although it’s not relevant here, I’m also using Sociable in single.php).

    Is there any way to set Sociable in index.php so it displays only for that first entry, and not for the excerpts?

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Paste it inbetween the same if statement that handles the full content for the first post, but right after the_content for that first post 🙂

    Doesn’t the_content handle the full content for each post?

    I have the Sociable script beneath the_content now. Above that is the beginning of the loop. The only “if” statement I see is if ( have_posts() ).

    I set Excerpt Editor to force excerpts of all posts following the first. Other than that, I’m hazy on how this thing works.

    Thanks.

    Please paste the entire loop in here, so I can tell you what to do, can’t tell you if I don’t know what code you’re running.

    Here’s my Loop:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
    
    		<div id="post-<?php the_ID(); ?>">
    
    		<p><?php the_content(); ?></p>
    
    <?php if (function_exists('sociable_html')) { echo sociable_html(Array("Digg", "del.icio.us", "StumbleUpon", "NewsVine", "Technorati", "Google", "YahooBuzz", "Reddit", "Facebook", "SphereIt", "Propellor", "TailRank", "email")); } ?>
    
    <p>Posted in:</em> <span id="tags"><?php the_category(', ') ?></span> at <?php the_time('g:i a'); ?> <?php the_time('D, M j, Y'); ?>.</p>
    
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><em>Permalink</em></a>&nbsp;&nbsp;•&nbsp;&nbsp;<?php edit_post_link('Edit', '', '&nbsp;&nbsp;•&nbsp;&nbsp;'); ?><?php comments_popup_link('Add a comment!', '1 comment', '% comments'); ?>
    
    		</div>
    
    		<?php endwhile; ?>
    
    <?php if(function_exists('wp_pagenavi')) { // if PageNavi is activated ?>   <?php wp_pagenavi(); // Use PageNavi ?>   <?php } else { // Otherwise, use traditional Navigation ?>   <div class="nav-previous"> <!-- next_post_link --> </div>   <div class="nav-next"> <!-- previous_post_link --> </div>   <?php } // End if-else statement ?>
    
    	<?php else : ?>
    		<h1><?php _e('Search again!'); ?></h1>
    	<p><img src="http://www.mysite.com/images/logo.jpg" width="60" height="57" alt=""><?php _e('No posts matched your criteria. Please try another term, or select a menu item to continue browsing.'); ?></p>
    
    	<?php endif; ?>

    Here goes, I guess this should work:

    <?php
    if (function_exists('sociable_html') && !$sociable_displayed) {
         echo sociable_html(Array("Digg", "del.icio.us", "StumbleUpon", "NewsVine", "Technorati", "Google", "YahooBuzz", "Reddit", "Facebook", "SphereIt", "Propellor", "TailRank", "email"));
      $sociable_displayed = true;
    } ?>

    Where you’d have to add this:
    <?php $sociable_displayed=false; ?>

    Outside of and before the loop.

    With your additional script, Sociable does appear in the first entry only. Looks great on the front page.

    But it continues to follow that pattern as you page through the entries (http://www.mysite.com/page/2/).

    I do appreciate the extra effort, but for consistency’s sake, I’ll stay with the original script.

    Thanks, joost!

    you could just add another parameter to the above if query:

    if (!$paged &&function_exists('sociable_html') && !$sociable_displayed) {

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Sociable] Display for first item only in index.php’ is closed to new replies.
Skip to toolbar