WordPress.org

Ready to get started?Download WordPress

Forums

UTW - ShowRelatedPostsForCurrentPost() in the Feed? (10 posts)

  1. Chris_K
    Member
    Posted 7 years ago #

    I'm wondering if there isn't a clever way to add the UTW function ShowRelatedPostsForCurrentPost() to my feeds?

    I've seen this article which sparked the idea. However, I wish to use the UTW related posts function and I hope to avoid core file modifying.

    Anyone done this -- or something like it -- with a plugin? Any pointers or thoughts?

  2. Chris_K
    Member
    Posted 7 years ago #

    The plus side: I can build a plugin. I can even make it work as far as modifying content goes.

    The negative side: I (apparently) can't just stuff the output from ShowRelatedPostsForCurrentPost() into a variable to add to the end of a feed.

    But I'm not a php ninja either. Is there a way to do that?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    I'm not entirely sure what you're trying to do, exactly. If you're wanting to add that data into the_content as a filter for the case of feeds, then yes, I see your problem. ShowRelatedPostsForCurrentPost() actually echoes, where you need it returned instead.

    This is probably not the cleanest way to do it, but it might work:

    function UTW_GetRelatedPostsForCurrentPost($formattype, $format="", $limit = 0) {
    global $utw, $post;
    $format = $utw->GetFormat($formattype, $format);
    return $utw->FormatPosts($utw->GetRelatedPosts($utw->GetTagsForPost($post->ID), $limit), $format);
    }
  4. Chris_K
    Member
    Posted 7 years ago #

    If you're wanting to add that data into the_content as a filter for the case of feeds[...]

    Exactly.

    Not completely sure I follow your example, but I'll go play with it for a bit and see where I end up.

    Right now I just have:

    function st_addRelatedtoFeed ($content) {
    	if ( ! is_feed() ) return $content;
    
    	$stutw = UTW_ShowRelatedPostsForCurrentPost("posthtmllist","",6);
    	$content = $content.$stutw;
       return ($content);
    }

    And you can spot pretty easily where it goes goofy. :-)

    Thanks!

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Try this:

    function UTW_GetRelatedPostsForCurrentPost($formattype, $format="", $limit = 0) {
    global $utw, $post;
    $format = $utw->GetFormat($formattype, $format);
    return $utw->FormatPosts($utw->GetRelatedPosts($utw->GetTagsForPost($post->ID), $limit), $format);
    }
    function st_addRelatedtoFeed ($content) {
    	if ( ! is_feed() ) return $content;
    	$stutw = UTW_GetRelatedPostsForCurrentPost("posthtmllist","",6);
    	$content = $content.$stutw;
       return ($content);
    }
  6. Chris_K
    Member
    Posted 7 years ago #

    You didn't let me go play yet!

    I'm glad to see that's about where I was headed though -- and a quick test shows it is definitely on the right track.

    Many thanks!

  7. Chris_K
    Member
    Posted 7 years ago #

    Thanks for your help Otto42!

    Plugin Released.

  8. Samuel B
    moderator
    Posted 7 years ago #

    I tried this - turned out to be pretty cool. Great idea, Handy.

    p.s. "Moderator+" ?
    Something wrong with "Supreme Ruler"?

  9. Chris_K
    Member
    Posted 7 years ago #

    Glad you liked it.

    (Moderator++ seemed overly geeky.)

  10. moshu
    Member
    Posted 7 years ago #

    I'll have to try this out - great idea.

    (will others get a minus? ;)

Topic Closed

This topic has been closed to new replies.

About this Topic