• Welcome to Simple Machines Community Forum. Please login or sign up.

If there is no image, use the default image?

Started by gecitli, October 14, 2021, 04:59:14 AM

Previous topic - Next topic

gecitli

Hello, I'm looking for a solution on this

code

If there is no image, use the default image

<header class="position-relative bg-secondary">';
if ($board['id'])
echo '<div class="node-img" style="background-image: url('.$settings['theme_url'].'/images/kategori/'.$board['id'].'.png);"></div>';
else // default add picture
echo '<div class="node-img" style="background-image: url('.$settings['theme_url'].'/images/kategori/'.$board['id'].'.default.jpg);"></div>';
  echo '
</header>

You cannot see attachments on this board.
http://www.webtiryaki.com
webmaster forumu
Free & Premium Responsive Themes for SMF.

Bugo

echo '
<header class="position-relative bg-secondary">';

if (file_exists($board_image = $settings['images_url'] . '/kategori/' . $board['id'] . '.png')
echo '<div class="node-img" style="background-image: url(' . $board_image . ');"></div>';
else // default add picture
echo '<div class="node-img" style="background-image: url(' . $settings['images_url'] . '/kategori/default.jpg);"></div>';

echo '
</header>';

gecitli

Quote from: Bugo on October 14, 2021, 07:48:59 AMecho '
<header class="position-relative bg-secondary">';

if (file_exists($board_image = $settings['images_url'] . '/kategori/' . $board['id'] . '.png')
echo '<div class="node-img" style="background-image: url(' . $board_image . ');"></div>';
else // default add picture
echo '<div class="node-img" style="background-image: url(' . $settings['images_url'] . '/kategori/default.jpg);"></div>';

echo '
</header>';


Bugo Thank you gives this error when I add the codes

QuoteParse error: syntax error, unexpected 'echo' (T_ECHO) in C:\wamp64\www\smf1\Themes\demo\BoardIndex.template.php on line 113

http://www.webtiryaki.com
webmaster forumu
Free & Premium Responsive Themes for SMF.

Diego Andrés

Looks like it's missing something at the end of the conditional
if (file_exists($board_image = $settings['images_url'] . '/kategori/' . $board['id'] . '.png'))

Quote from: Bugo on October 14, 2021, 07:48:59 AMecho '
<header class="position-relative bg-secondary">';

if (file_exists($board_image = $settings['images_url'] . '/kategori/' . $board['id'] . '.png'))
echo '<div class="node-img" style="background-image: url(' . $board_image . ');"></div>';
else // default add picture
echo '<div class="node-img" style="background-image: url(' . $settings['images_url'] . '/kategori/default.jpg);"></div>';

echo '
</header>';


SMF Tricks - Free & Premium Responsive Themes for SMF.

gecitli

This is overlooked

if (file_exists($board_image = $settings['images_url'] . '/kategori/' . $board['id'] . '.png'))
only this code takes a default image, it does not freeze the code
http://www.webtiryaki.com
webmaster forumu
Free & Premium Responsive Themes for SMF.

Bugo

global $settings;
if (file_exists($settings['theme_dir'] . '/images/kategori/' . $board['id'] . '.png'))

echo '
<header class="position-relative bg-secondary">';

global $settings;
if (file_exists($settings['theme_dir'] . '/images/kategori/' . $board['id'] . '.png'))
echo '<div class="node-img" style="background-image: url(\'' . $settings['images_url'] . '/kategori/' . $board['id'] . '.png\');"></div>';
else
echo '<div class="node-img" style="background-image: url(\'' . $settings['images_url'] . '/kategori/default.jpg\');"></div>';

echo '
</header>';

Advertisement: