• Resolved anachros

    (@anachros)


    Hi,

    I’m new to Post Snippets but I got one up and working beautifully, using PHP to load some information from an outside API.

    Next, I realized I wanted to display the same information twice on my page. A summary form near the top and a longer display later. Rather than duplicate the code, I thought I’d incorporate the same Post Snippet in both places, with a variable called display_type to let it know which format to print in each place. When I tried to save my page with this, WordPress broke entirely (displayed a blank page instead of the Editor screen).

    I tried everything I could think of, but I can’t find a way around it. I even tried making a second copy of my PostSnippet with identical code but a different name and different variable names. Surely the two versions won’t interfere with each other in that case—but alas, if I try to save the page it breaks horribly and WordPress gives me a blank screen where I should see the Editor.

    [MyPostSnippet source=”url” display_type=”small”]
    [MyPostSnippet2 source_2=”url” display_type_2=”verbose”]

    I’m really not sure what to do. Is it true that only one Post Snippet can be included on any WordPress page, and it can only be included once? Or is there some trick I’m not seeing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter anachros

    (@anachros)

    I defined a function in my Post Snippet. Including the second Post Snippet attempted to define a function that was already defined. You can’t do that!

    I wrapped it in a conditional if(!function_exists('foo')){ and everything got a lot better. I’ll leave this here in case anyone else makes the same mistake I did.

    Good find, glad you got it sorted out!

    Thanks, useful info

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple Post Snippets in one page’ is closed to new replies.