-1

I don't even know how to ask this clearly so I apologize for any confusion.

Basically I'm trying to store html in hoverHTML whereby if $img['socialfb'] contains a value it will concatenate the <li> element that displays the correct social icon and if not, it moves on. This would eventually include other social icon link items.

$hoverHTML = '<div class="thumbnail-overlay">
                <h2><a href="'.$img['link'].'"> '.$img['data']->post_title.'</a></h2>
                    <ul class="socials">'
                        (isset($img['socialfb']) ? .'<li><a href="'.$img['socialfb'].'"><i class="fab fa-facebook"></i></li>'. : .''.)                          
                   '</ul></div>';
return $hoverHTML;

Is this even possible? I'm still very new to php but trying to mod an existing plugin.

Here is the full function:

function getHover( $img ){
        $hoverHTML = '';
        if(!$this->hover) return $hoverHTML;
        if($this->hover == 1){
            $hoverHTML .= $this->titleHover;
            if( $this->linkIcon || $this->zoomIcon ){
                $hoverHTML .= '<div class="rbsIcons">';
                if($this->linkIcon && $img['link']) $hoverHTML .= '<a href="@LINK@" '.($img['typelink']?'target="_blank"':'').' title="@TITLE@">'.$this->linkIcon.'</a>';
                if($this->zoomIcon) $hoverHTML .= $this->zoomIcon;
                $hoverHTML .= '</div>';
            }
            $hoverHTML .= $this->descHover;
        }

        if($this->templateHover) $hoverHTML = $this->templateHover; 

        if($hoverHTML){             
            $hoverHTML =  str_replace( 
                array('@TITLE@','@CAPTION@','@DESC@', '@LINK@', '@SOCIALFB@'), 
                array( 
                    $img['data']->post_title,
                    $img['data']->post_excerpt,
                    $img['data']->post_content,
                    $img['link'],
                    $img['socialfb'],
                ), 
                $hoverHTML
            );
        }
        $hoverHTML = '<div class="thumbnail-overlay">
                        <h2><a href="'.$img['link'].'"> '.$img['data']->post_title.'</a></h2>
                        <ul class="socials">'
                            (isset($img['socialfb']) ? .'<li><a href="'.$img['socialfb'].'"><i class="fab fa-facebook"></i></li>'. : .''.)                          
                        '</ul>

                      </div>';
        return $hoverHTML;
    }
NikF
  • 21
  • 7
  • 1
    yes this is possible, can you show full function code? – RainDev Jul 08 '18 at 00:31
  • Sure you can, but the result of the ternary operator will be whatever its value was when you set the variable. It won’t update automatically if you change things later, if that’s what you’re asking. – elixenide Jul 08 '18 at 00:32
  • Your syntax is wrong, though. You can’t use (and don’t need) the `.`s before and after the `?` and `:`. You would just put the dots before and after the `(` and `)` that enclose your ternary expression. – elixenide Jul 08 '18 at 00:33

1 Answers1

0

So yes you can, but you have syntax error change $hoverHTML to this:

$hoverHTML = '<div class="thumbnail-overlay">
            <h2><a href="'.$img['link'].'"> '.$img['data']->post_title.'</a></h2>
                <ul class="socials">'
                    .(isset($img['socialfb']) ? '<li><a href="'.$img['socialfb'].'"><i class="fab fa-facebook"></i></li>' : '').                          
               '</ul></div>';
return $hoverHTML;
RainDev
  • 1,098
  • 8
  • 9
  • Thanks, you're right. Turns out the real problem was that isset() was returning true but it didn't contain the information I needed it to, a url. I used `filter_var($img['socialfb'], FILTER_VALIDATE_URL)` and this produced the desired result. – NikF Jul 08 '18 at 00:45