Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>comparing the hard coded javascript to ones that don't work, I notice that you are not including the double-quotes around the <code>&lt;?php $article["img"]; ?&gt;</code> snippet. The hard coded one shows</p> <pre><code>= 'url("img/gym-01.jpg")' </code></pre> <p>but the ones with the php snippet will produce</p> <pre><code> = 'url(img/gym-01.jpg)' </code></pre> <p>so perhaps if you modify it to</p> <pre><code>document.getElementById('news-img-1').style.backgroundImage = 'url("'&lt;?php $article["img"]; ?&gt;'")'; </code></pre> <p>OR</p> <p>edit the <code>get_news_feed</code> function as follows:</p> <p>replace these lines</p> <pre><code>$output .= '&lt;div id="news-img-1"&gt;'; $output .= "&lt;/div&gt;"; </code></pre> <p>with</p> <pre><code>$output .= '&lt;div class="news-img"&gt;&lt;img src="' . $article["img"] . '"&gt;&lt;/div&gt;' ; </code></pre> <p>and change your css like so:</p> <pre><code>article.img-wrapper { position: relative; } div.news-img { position: absolute; top: 0; z-index: -1000; } </code></pre> <p>OR</p> <p>Modify your get_news_feed function, change the statement for the <code>&lt;div id="news-img-1"&gt;</code> output to include a data-url attribute like:</p> <pre><code>$output .= '&lt;div class="news-img" data-url="' . $article["img"] . '"&gt;'; </code></pre> <p>Then add a jquery statement like:</p> <pre><code>$(".news-img").each( function() { $(this).css("background-image", "url(" + $(this).data("url") +")" ); }); </code></pre> <p>The jquery statement goes in a static js file as opposed to generating the script in php.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload