WordPress.org

Ready to get started?Download WordPress

Forums

Recent Posts Widget Extended
Excepts pulling text from the current page's template and not from recent posts (16 posts)

  1. KACramer
    Member
    Posted 4 months ago #

    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/

  2. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

    Are you using the latest version?

  3. KACramer
    Member
    Posted 4 months ago #

    @satrya I think so... Version 0.9?

  4. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

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

  5. KACramer
    Member
    Posted 4 months ago #

    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/

  6. KACramer
    Member
    Posted 4 months ago #

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

    Will try this now. Just a second... Thanks!

  7. KACramer
    Member
    Posted 4 months ago #

    Nope. Didn't work. :(

  8. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

    Ok, I guess this is a bug from my plugin. I will fix it soon :)

  9. KACramer
    Member
    Posted 4 months ago #

    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 :)

  10. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

    You're welcome :)

  11. KACramer
    Member
    Posted 4 months ago #

    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;
    }
  12. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

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

  13. KACramer
    Member
    Posted 4 months ago #

    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?

  14. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

    No, please just change the function above

  15. KACramer
    Member
    Posted 4 months ago #

    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?

  16. Satrya
    Member
    Plugin Author

    Posted 4 months ago #

    oh ok, for now you can use your code

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.