WordPress.org

Support

Support » Plugins and Hacks » Recent Posts Widget Extended » Excepts pulling text from the current page's template and not from recent posts

Excepts pulling text from the current page's template and not from recent posts

  • I am using a plugin from Modern Tribe called Community Events and it works in tandem with Modern Tribe’s Event Calendar Pro. Anyway, the Recent Posts Widget works fine on every page EXCEPT the ones which are using the Community Events plugin… this plugin creates a submission form that people can use to submit events to our calendar. The form is content is generated by a file titled edit-events.php. I have gone through this with a fine tooth comb and have added the following code to the bottom of the page:
    <?php wp_reset_query(); ?>
    Unfortunately, this has had no effect. The folks at Modern Tribe will not help me. I would use a seperate template for the submission form (omitting the recent blog posts plugin for that single page), BUT I can’t as you can only use one page template for both the submission form and the main calendar pages. I am not sure where I should begin…

    Here is the page that is “messing-up” (for lack of a better term):
    http://www.sciotomile.com/events/submission/add

    Notice that on the regular calendar pages the plugin works fine:
    http://www.sciotomile.com/events/

    Here is the code for the file that creates the submission form:
    http://pastebin.com/RdPdBK0g

    Here is the template I am using for these event pages:
    http://pastebin.com/x7dg12Hj
    I don’t think it is this template file though since the calendar pages use this template as well and the plugin works fine on those pages.

    https://wordpress.org/plugins/recent-posts-widget-extended/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Are you using the latest version?

    @satrya I think so… Version 0.9?

    Could you try to put <?php wp_reset_postdata(); ?> not <?php wp_reset_query(); ?>

    Here is what the guy on the Modern Tribe Events Calendar forum told me:

    The Community add-on uses custom routing and re-writes the WordPress loop in order to display the Event Submission form and other pages. I would suggest modifying the rpwe_excerpt() function to get the excerpt using the post ID. Here’s a good example of getting the_excerpt outside of the WordPress loop: http://uplifted.net/programming/wordpress-get-the-excerpt-automatically-using-the-post-id-outside-of-the-loop/

    I would try using that as an example to re-write the rpwe_excerpt() function and see if that does the trick. I hope that points you in the right direction, and feel free to let me know if you have further questions. Thanks

    Not sure if this helps… He can’t help me beyond that…

    https://tri.be/support/forums/topic/screws-up-recent-post-widget-on-sidebar/

    Could you try to put <?php wp_reset_postdata(); ?> not <?php wp_reset_query(); ?>

    Will try this now. Just a second… Thanks!

    Nope. Didn’t work. πŸ™

    Ok, I guess this is a bug from my plugin. I will fix it soon πŸ™‚

    Ok, I guess this is a bug from my plugin. I will fix it soon πŸ™‚

    Wow… thanks! I wouldn’t really call it a “bug”, as the widget works beautifully on most pages… it is just the interaction between the two plugins. But I really, really appreciate all your help πŸ™‚

    You’re welcome πŸ™‚

    I fixed it by doing this… It may not be the cleanest way to go about it.

    I added the following code to my theme functions file (functions.php):

    function get_excerpt_by_id($post_id){
    $the_post = get_post($post_id); //Gets post ID
    $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
    $excerpt_length = 800; //Sets excerpt length by word count
    $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
    $words = explode(' ', $the_excerpt, $excerpt_length + 1);
    if(count($words) > $excerpt_length) :
    array_pop($words);
    array_push($words, '…');
    $the_excerpt = implode(' ', $words);
    endif;
    $the_excerpt = '<p>' . $the_excerpt . '</p>';
    return $the_excerpt;
    }

    And then I changed the code in recent-posts-widget-extended/includes/widget-recent-posts-extended.php… I changed the function rpwe_excerpt by replacing “get_the_excerpt()” with “get_excerpt_by_id($post_id)” as follows:

    function rpwe_excerpt( $length ) {
    	$content = get_excerpt_by_id($post_id);
    	$excerpt = wp_trim_words( $content, $length );
    
    	return $excerpt;
    }

    Would you please try to change <?php echo rpwe_excerpt( $length ); ?> with <?php echo wp_trim_words( get_the_excerpt(), $length ); ?>

    I will need to edit:

    function rpwe_excerpt( $length ) {
    	$content = get_excerpt_by_id($post_id);
    	$excerpt = wp_trim_words( $content, $length );
    
    	return $excerpt;
    }

    before changing <?php echo rpwe_excerpt( $length ); ?> to <?php echo wp_trim_words( get_the_excerpt(), $length ); ?>

    Right?

    No, please just change the function above

    When I made that change, it stopped working again… the way it did before I made my earlier change. Maybe if you used get_excerpt_by_post function instead of get_the_excerpt?

    oh ok, for now you can use your code

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Excepts pulling text from the current page's template and not from recent posts’ is closed to new replies.
Skip to toolbar