2

I asked this question, which i got solved pretty quickly with help: Reverse the way of function output

However, when i do what is suggested, it breaks the way that the javascript is working.

If i do this

$output = '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">' . $output;

Instead of this:

$output .= '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">'

the javascript stops working. But the output is reversed, as it should be. How can this be solved, but still having the output reversed?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Patrick
  • 166
  • 2
  • 14
  • 1
    Just a minor commenty thing; why not use [heredocs](http://stackoverflow.com/a/5673478/899126) for holding multi-line strings, especially since you can still embed variables within them? – Chris Forrence Oct 28 '14 at 18:58
  • More relevant: what do you mean that it breaks the way that JavaScript is working? Does anything appear in the console log? If you view the page source, does the resulting HTML look correct? – Chris Forrence Oct 28 '14 at 19:01
  • @ChrisForrence Uh, heredocs i have not worked with before - i will look into this, thanks! - The page source is completely the same, no matter how the output is generated. This is one of the reasons why i don't see how this cannot work. – Patrick Oct 28 '14 at 19:21

1 Answers1

0

In your example this

$output = '<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'">' . $output;

would create this $output:

<a class="w-portfolio-item-anchor" href="javascript:void(0);" data-id="'.$post->ID.'"><div class="w-portfolio">
                        <div class="w-portfolio-h">
                            <div class="w-portfolio-list">
                                <div class="w-portfolio-list-h">

Tip: Use var_dump($output) or echo $ouput in your code so you can see what's stored in the $output variable. As it seems with your current code you will have a messed HTML structure.

EDIT:

You are initializing the $output variable outside of the loop on line 35. I'm writing now some pseudocode how your code should work:

    //line 34
    $output =   '<div class="w-portfolio"> 
                    <div class="w-portfolio-h">
                        <div class="w-portfolio-list">
                            <div class="w-portfolio-list-h">';

    foreach( $posts as $post ) {  // Note: This is the while loop in your example

        $output .= '<a href="javascript:void(0);" data-id="'.$post->ID.'">'; //notice the .= which appends the string to variable declared on line 35

    }
    $output .=              '</div>
                        </div>
                    </div>
                </div>';

    return $output;

Don't use $output .= $output or $output = 'bla bla' . $ouput anywhere here. That would break the HTML structure you want to create with your code. Be conscious your $output variable starts with $output = '<div class="w-portfolio">.


Please remove the . $output; from </div>'. $output; on line 105 in your code.

Try this PasteOfCode

pbaldauf
  • 1,671
  • 2
  • 23
  • 32