WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin Category Shortcode] Wrong links (edit, permalink, etc) on parent page (10 posts)

  1. g33kg0dd3ss
    Member
    Posted 4 years ago #

    Hello!

    I've been hacking away at the Category Shortcode plugin and have successfully added several new options. I've noticed, however, that the original code has an odd side effect, and while I haven't been able to fix it, I've been able to narrow it down to a specific function used in the plugin.

    The "Edit," "Permalink," and "Trackback" links on the parent page are those for the last displayed child page, and not for the parent page. You can see it in action here:
    http://g33kg0dd3ss.com/shop/
    You'll notice that the links at the bottom that should point to the "/shop" page are instead pointing to the "Wobblecog Necklace" post.

    The problem *seems* to be with the set_postdata() call (first used on line 94 in the original code). The surrounding code looks a bit like this:

    90: global $post;
    ...
    93: foreach($rdcsc_posts as $post) :
    94:     setup_postdata($post);
    95:     $rdcsc_excerpt = get_the_excerpt();

    I've tried renaming certain variables or using different template tags, but nothing so far has worked. Here's where I hope you lovely folks come in! :) Is there a way to fix this problem?

  2. robertdrake
    Member
    Posted 4 years ago #

    Unless I'm missing something, the permalink and trackback link at the bottom of your page are directed correctly. Permalink goes to http://g33kg0dd3ss.com/shop/ and the trackback goes http://g33kg0dd3ss.com/shop/trackback/?

  3. g33kg0dd3ss
    Member
    Posted 4 years ago #

    Sorry, I've been playing with the code again. :) The page should be displaying properly now. (Well, as properly as it's ever been.)

  4. robertdrake
    Member
    Posted 4 years ago #

    This weekend I'll see if I can delve into the issue a little deeper, but I saw something similar to this once before where the post loop was basically overwriting all of the information for the page by the time it displayed it. I never found a really satisfactory solution from a plugin standpoint, but I was able to code around it by making a page template that explicitly pulled in the link for the displayed page. That may work for you as a solution - at least a temporary one.

    And if you or anyone else finds something - I'd be more than happy to merge the patch into my code and drop some acknowledgments into the description.

  5. robertdrake
    Member
    Posted 4 years ago #

    There may be something to the reset query function to look into...

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Also as an idea, it should be possible to run the loop after the plugin runs and reacquire the original page's data. I'm not sure that's a good way of doing it from a coding standard viewpoint...I'd need to delve a little more into wordpress' coding guidelines I guess.

  6. g33kg0dd3ss
    Member
    Posted 4 years ago #

    Thanks for the insight, Robert! I'll keep digging around and see what I come up with, then post it here.

  7. g33kg0dd3ss
    Member
    Posted 4 years ago #

    Aha! I'd been looking into wp_reset_query() when you mentioned it. After a bit more poking, I found that adding it toward the bottom of the rdrakeCategoryShortcode_function() function does the trick, like so:

    156: wp_reset_query();
    157: $rdscf_output.='';
    158: return $rdscf_output;

    It has to be in that particular location; placing it at the very end of the function (before the closing }) essentially nullifies it.

  8. robertdrake
    Member
    Posted 4 years ago #

    I'll run a few tests this weekend and roll that into a patch. Thank you very much for the assistance with this!

  9. robertdrake
    Member
    Posted 3 years ago #

    Released version 1.3 with your patch. Thank you again for your work with this.

  10. g33kg0dd3ss
    Member
    Posted 3 years ago #

    No problemo! Glad to have helped. :)

Topic Closed

This topic has been closed to new replies.

About this Topic