Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im trying to use the_excerpt form inside a plugins template file, plugin is wp-favorite-posts by default the plugin only lists and displays the saved post title, i have manged to get it to show everything, tax terms, image etc but having a heck of a time with the_excerpt, what happens when i add <?php the_excerpt( $post_id ); ?> into the code is a continual looping of the favorite post and no excerpt.

Im using global $post so that i can get all the info (cept the excerpt)

<?php

global $post;

if (!empty($user)):
    if (!wpfp_is_user_favlist_public($user)):
        echo "$user's Favorite Posts.";
    else:
        echo "$user's list is not public.";
    endif;
endif;

if ($wpfp_before):
    echo "<p>".$wpfp_before."</p>";
endif;


if ($favorite_post_ids):
    foreach ($favorite_post_ids as $post_id) {
       $p = get_post($post_id); ?>

       <div class="homepage_props">

           <div class="homepage_props_inner">
               <div class="homepage_propsbanner">
                   <div class="homepage_new">
                       <?php if (strtotime($post->post_date) > strtotime('-7 days')) { ?>
                           <img src="<?php echo get_template_directory_uri(); ?>/images/new.png" alt="latest property listings" />
                       <?php } ?>
                   </div>
                   <h2>
                       <span style="float:left; font-weight:bold;">
                           <?php 
                           if ( 'sales' == get_post_type($post_id) ) { 
                               echo 'Property For Sale';
                           } elseif ( 'rentals' == get_post_type($post_id) ) { 
                               echo 'Property For Rent'; 
                           } elseif ( 'business' == get_post_type($post_id) ) { 
                               echo 'Business For Sale</span>'; 
                           } elseif ( 'bandb' == get_post_type() ) { 
                               echo 'Bed And Breakfast</span>'; 
                           }
                           ?>

                        </span>
                        <span style="float:right; font-weight:normal;">
                            <a href="<?php echo get_permalink($post_id); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themename' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo get_the_title ( $post_id ); ?></a>
                        </span>
                    </h2>
                </div>

                <div class="clear"></div>
                <div class="homepage_props_image">

                    <?php  
                    echo "<a href='".get_permalink($post_id)."'>";
                    echo get_the_post_thumbnail ( $post_id, 'medium' );
                    echo "</a>";
                    ?>

                </div><!-- / homepage_props_image -->

                <div class="homepage_props_info hyphenate">

                    <!-- heres where im trying to put the_excerpt -->

                </div><!-- / homepage_props_info -->
                <div class="clear"></div>

                <div class="homepage_props_tax">

                    <?php
                    if ( 'sales' == get_post_type($post_id) ) { 
                        echo '<h3><span style="float:right; font-weight:normal;">' . get_the_term_list( $post_id, 'property_type', 'Property Type: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' . get_the_term_list( $post_id, 'location', 'Location: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;'.get_the_term_list( $post_id, 'region', 'Region: ', ' ', '' );
                    } elseif ( 'rentals' == get_post_type($post_id) ) { 
                        echo '<h3><span style="float:right; font-weight:normal;">' . get_the_term_list( $post_id, 'property_type', 'Property Type: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' . get_the_term_list( $post_id, 'location', 'Location: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' . get_the_term_list( $post_id, 'region', 'Region: ', ' ', '' );
                    } elseif ( 'business' == get_post_type($post_id) ) { 
                        echo '<h3><span style="float:right; font-weight:normal;">' . get_the_term_list( $post_id, 'property_type', 'Property Type: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' . get_the_term_list( $post_id, 'location', 'Location: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' . get_the_term_list( $post_id, 'region', 'Region: ', ' ', '' ); 
                    } 
                    ?>
                    </span></h3>
                </div><!-- / homepage_props_tax -->          

            </div><!-- / homepage_props_inner -->

        </div><!-- / homepage_props -->

    <?php
    }
else:

    echo $wpfp_options['favorites_empty'];

endif; ?>
<span style="float:left; font-size:0.7em;"><?php wpfp_clear_list_link(); ?></span>
<?php wpfp_cookie_warning(); ?>  

First picture is using the_excerpt

with the_excerpt

Second picture is without the_excerpt
without the excerpt

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You are doing few things wrong:

  1. the_excerpt does not uses post id.
  2. When you modify global $post you should always set it back to its original value.
  3. you were assigning get_post's return value to $p which was not used in your code.

I have made few fixes in your code. The below code is just the copy paste of your code with my fixes so try the code below and let me know if you still have issues. Sorry I had to change bit of your code formatting.

<?php
    if (!empty($user)):
        if (!wpfp_is_user_favlist_public($user)):
            echo "$user's Favorite Posts.";
        else:
            echo "$user's list is not public.";
        endif;
    endif;

    if ($wpfp_before):
        echo "<p>".$wpfp_before."</p>";
    endif;

    if ($favorite_post_ids):
        foreach ($favorite_post_ids as $post_id) {
            $p = get_post($post_id);
?>
      <div class="homepage_props">

                       <div class="homepage_props_inner">
                            <div class="homepage_propsbanner">
                                <div class="homepage_new">
                                <?php if (strtotime($p->post_date) > strtotime('-7 days')) { ?>
                                    <img src="<?php echo get_template_directory_uri(); ?>/images/new.png" alt="latest property listings" />
                                <?php } ?>
                                </div>
                                <h2><span style="float:left; font-weight:bold;">
                                <?php 
                                    if ( 'sales' == $p->post_type ) { 
                                        echo 'Property For Sale'; 
                                    } elseif ( 'rentals' == $p->post_type ) {
                                        echo 'Property For Rent'; 
                                    } elseif ( 'business' == $p->post_type ) { 
                                        echo 'Business For Sale'; 
                                    } elseif ( 'bandb' == $p->post_type ) {
                                        echo 'Bed And Breakfast'; 
                                    } 
                                ?>
                                </span>
                                <span style="float:right; font-weight:normal;">
                                    <a href="<?php echo get_permalink($post_id); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themename' ), get_the_title( $post_id ) ); ?>" rel="bookmark"><?php echo get_the_title ( $post_id ); ?></a>
                                </span>
                                </h2>
                            </div>

                            <div class="clear"></div>
                                  <div class="homepage_props_image">
<?php  

        echo "<a href='".get_permalink($post_id)."'>";
        echo get_the_post_thumbnail ( $post_id, 'medium' );
        echo "</a>";

?>
                                   </div><!-- / homepage_props_image -->

                                           <div class="homepage_props_info hyphenate">

                                           <?php echo $p->post_excerpt; ?>

                                           </div><!-- / homepage_props_info -->

                                                     <div class="clear"></div>

                                            <div class="homepage_props_tax">

                                    <?php 
                                        if ( in_array( $p->post_type, array( 'sales', 'rentals', 'business' ) ) ) {
                                            echo '<h3><span style="float:right; font-weight:normal;">' .get_the_term_list( $post_id, 'property_type', 'Property Type: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;' .get_the_term_list( $post_id, 'location', 'Location: ', ' ', '' ),'&nbsp;&nbsp;&nbsp;'.get_the_term_list( $post_id, 'region', 'Region: ', ' ', '' );
                                            echo '</span></h3>';
                                        } 
                                    ?>
                                            </div><!-- / homepage_props_tax -->



                   </div><!-- / homepage_props_inner -->

                 </div><!-- / homepage_props -->

<?php
        }
    else:
        echo $wpfp_options['favorites_empty'];
    endif;
?>
share|improve this answer
    
Thankyou Hameedullah for taking the time to help, i have tried your code provided and the same thing still happens, i have edited my Opening post to show the error, the first picture shows what happens when the_excerpt is included in the code and the second picture shows how it looks when the excerpt is not in the code, both your way and my way result in the same error.. regards –  MartinJJ Jun 16 '11 at 10:01
    
@Martin, I have made the modification to the code in my answer to use $post->post_excerpt instead of the_excerpt can you please try it just to be sure. –  Hameedullah Khan Jun 16 '11 at 10:31
    
@Hameedullah thanks, that has stopped the looping that is shown in the images above, but has just left the css and shows none of the values ie: thumbnail, titles, excerpt etc.. –  MartinJJ Jun 16 '11 at 10:37
    
@Martin, What do you mean by left the css? formatting is broken or something else? Can you try echo strip_tags( $post->post_excerpt ); –  Hameedullah Khan Jun 16 '11 at 10:48
    
@Hameedullah by leaving just the css, i maybe should have been clearer and said that it leaves my html rendered on the page as it should be but none of the dynamics (text and thumbnail) are being called so im basically just left with an empty but styled div. The last bit of code above you provided is also the same not getting any output via php at all.. sorry about the time your spending on this, but it is appreciated.. im at a complete loss of how to get around it to be honest –  MartinJJ Jun 16 '11 at 10:54
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.