Home Forums Weaver X Tutorials and Hints tutorial to add and display custom post

This topic contains 21 replies, has 3 voices, and was last updated by  scrambler 2 years, 5 months ago.

Viewing 6 posts - 17 through 22 (of 22 total)
  • Author
    Posts
  • #29177

    davidm
    Participant

    Hi Weaver, thanks for your reply. One of the best things about this theme is that there’s someone to talk to.
    Before you replied I played around a little more trying to get my shortcode plugin to work. I added wp_reset_postdata() just before return $output and for reasons which I don’t understand it’s now working – each custom post displaying as a formatted table row, but I’m worried about your warnings about “messing up instances of the loop used by page or post processing”, I still don’t understand why the loop inside the plugin should have any influence over loops elsewhere, but if you think this is a risk I’ll try and implement [show_posts] as you suggest.
    Thanks for your help.
    David

    #29178

    scrambler
    Moderator

    I don’t think he meant that the loop you would use in a specific page would influence other pages, but more it you use your loop in a page that already has one.

    In any case, if it messes something you will see it. If your pages work fine, you should be OK

    #29179

    Weaver
    Keymaster

    The WordPress loop is not designed to be recursive, to use the technical term. And whenever you display a page or a post, there is a top level instance of the loop. For one thing, once your are inside the loop, a bunch of values to the WP global $WP_Query are set. If you then try to create or use another instance of the loop, the top level “gets lost” – all the values are gone, so nothing works right.

    If you do create a new instance of the loop, using

    wp_reset_query();
    wp_reset_postdata();

    at the end of your use of the loop, then the previous values of the loop are reset.

    It is not exactly that simple, but mostly that works if your instance of the loop is simple, and the original loop isn’t inside displaying a bunch of posts. In other words, if the top level is a page, things are simpler. Nesting posts inside of posts can easily create additional issues – the paging of posts, for example. 

    Just FYI, it took us months or more to get [show_posts] to work right with most themes and other instances of the loop. Because of inherent limitations in the WP implementation of the loop, [show_posts] and the Page with Posts template will still not display things correctly if a post displayed with [show_posts] also uses [show_posts]. No recursion!

    #29180

    davidm
    Participant

    Thanks so much Weaver for clarifying the situation and giving such a clear explanation, much appreciated, now finally I can move on.

    #29181

    davidm
    Participant

    Hi Weaver
    Tried your suggestion
    If the actual content of your custom post type is already
    formatted as a table that would fit under you table header stuff, then
    you might be able to use the Weaver Show Posts short code to display a
    defined set of your custom posts. – put the header on a standard page,
    and use [show_posts] to display your posts.

    The problem is if I put the table header on a standard page followed by [show-posts] the individual posts lose the table format (the td elements display vertically, not horizontally ) ’cause they’re missing the <table> header part

    Or am I doing something wrong?

    Thanks for your help
    David

    #29182

    scrambler
    Moderator

    provide the html you are using with a more detailed explanation of what you are trying to put together

Viewing 6 posts - 17 through 22 (of 22 total)

You must be logged in to reply to this topic.