Thumbnail image does not appear on website - php

I have a problem in my wordpress theme.
The thumbnail doesn't appear on every post.
I have a website with games and every game has a thumbnail (image) . But now the image doesn't appear. When I try to see the image I get this:
Invalid src mime type:
The problematic code is:
<img src="<?php bloginfo('template_url');?>/thumb.php?src=<?=$thumb;?>&w=183&h=140&zc=1" class="thumb" alt="<?php the_title(); ?>" />
What might be wrong?

Browsing to your site I saw what the issue is. If you look at your code, it's being generated like this:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?=$thumb?>... ?>
It seems that your PHP parser isn't picking up the php in the tag. Try using this instead:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?php=$thumb?>... ?>
It's possible your php configuration doesn't allow for "short-tags"
<?
code here
?>
but instead require the full php tags, which are:
<?php
code here
?>
You might be able to override this in your php.ini, but if you don't have access to that, simply use the full php tags and you should be good to go.
<?php echo $thumb; ?>

Related

Setting SRC of an image using Wordpress get_option

I am trying to use the get_option() function in Wordpress to set the SRC of an image in a theme file. The file is index.php, and represents the homepage.
The current image code is:
<img class="outside-collage-image" <?php echo 'src="'.get_option('article-image-1').'"'; ?>>
However, the image doesn't display, and when I inspect it, it simply says src(unknown) where it should have the proper SRC
I have tried a myriad of fixes, including leaving the SRC out of the php area and simply calling the function, but it doesn't seem to work.
The oddest part is, if I put on the page <p><?php echo 'src="'.get_option('article-image-1').'"'; ?></p> to check the output, it outputs into the <p> the proper code: src="http://image-site.com/my-image.jpg" (obviously the link to the image is fake, but the point is, it's a valid link.)
Any idea what could be causing this?
You can try this to get the image article-image-1.jpg in your root.
<img class="outside-collage-image" src="<?php echo get_site_url().'/article-image-1.jpg'; ?>">
It turns out that I screwed up, and the above function works just fine. I was simply applying it to the wrong image, and didn't realize that until looking at it a day later, when it wasn't 1:30 AM and I wasn't so tired. Thanks to all that answered.
headdesk

image is not getting displayed on the web page .instead the text "loading..." is being displayed

my image is saved in a file ....and i have saved its path in the database....when i am fetching the image path from the database and trying to display it on a given position on the web page it is simply not getting displayed instead a text "loading..." is appearing there
furthermore the inspect element is displaying the image path clearly, here it is
'<img id="image" alt="mgm axis" title="mgm axis" src="polybazaar_files/images/1.jpg" style="display: block;"></img>'
now part of my code is here
while( $result=mysqli_fetch_array($runquery))
{$GLOBALS['image']=$result['image'];}
<img src="<?php echo $image; ?>" title="<?php echo $prodname; ?>" alt="<?php echo $prodname; ?>" id="image" />
where on a different page echo'<img src="'.($result['image']).'" />'; worked for the same image on the database....
i tried the suggestion mentioned here Displaying an image using a php variable and also tried suggestion mentioned at other places but none of them work
also my page has lot of java script in between ......are they creating problem?
any valuable and informative reasons or solutions will be appreciated ....thanks
got it fixed .....
actually the address at the top of my script
<base href="http://polybazaar.in/shop/" />
needed to be put inside the comment, since i am working on a local server....or the address of a DEFAULT TARGET should be given if one wants its server request to be accessed from that URL.....
thanks all for their valuable comments

Load relative path of images instead of <?php echo $img ?>

The timthumb function is not working after the security setting of web server is raised.
Images with "http://...." in URL are blocked.
I have found that <?php echo $img ?> was used to load the image.
Original code:
<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=100&w=100&zc=1&src=<?php echo $img ?>" alt="<?php the_title_attribute(); ?>" width="100" height="100" />
Would someone please tell me how can I modify the code so that instead of
http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=http://domain.com/wp-content/uploads/thumbnail.jpg
the image URL will be
http://domain.com/wp-content/themes/a/scripts/timthumb.php?h=100&w=100&zc=1&src=../wp-content/uploads/2013/10/thumbnail.jpg
?
The code inside timthumb.php is super long. I will post the code if it's needed.
I know almost nothing about php code and only use plugins to build Wordpress websites.
You would have save my life. Thank you very very much!
It depends on where it is getting $img value from. If this is just a field on your article (through the extra parameters on the bottom), you could simply alter the url in your post. Alternatively, you could process the path, stripping out the http://domain.com/ and replace it with ../,
a la:
$img = str_replace("http://domain.com/", "../", $img);
just before echoing it out on to the page.

how calling the images in a folder with php

I want to ask about calling the images in a folder with php
The first I've made ​​a file to declare the image url
$url_folder_gambar = 'http://localhost/mysite/assets/img/';
I then call the php but the picture did not come out. what's wrong?
<img src="<?php echo $url_folder_gambar . people.png?>"
please help me
It looks like a syntax error. Try this:
<img src="<?php echo $url_folder_gambar;?>people.png" />
$url_folder_gambar path of the image file, some thing like http://domain/path/imagefolder/
<img src="<?php echo $url_folder_gambar;?>people.png" >
OR
<img src="<?php echo $url_folder_gambar.'people.png';?>" >
Check browser code view source using ctrl+u, check the file path, and copy the source url and pasted into the borwser, whether it is rendered or not, If not there is no file in that location.

How to add images to a wordpress theme when working on MAMP?

I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.com
When adding an image directly to the code I used:
<img src="<?= $theme ?>/images/logo.png"/>
But the image is not showing up, also I tried to add it to the media library and it's still not rendering.
This works for me:
<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
See get bloginfo() function for more info.
You can use the following code to add an image. This works for me:
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
<?php echo get_template_directory_uri(); ?>
as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url
<img src="your/copied/url"/>
This aslo works for me in localhost
You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>
Update I didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg
In short, if you uploaded it in media, it wouldn't actually be in your theme.
<?php bloginfo('template_directory'); ?>/
use for internal root folder in images to place on theme on wordpress.
The forward slash is needed for the image to show
Remove the = after <?
<img src="<? $theme ?>/images/logo.png"/>
in fact, I'd probably do something like this:
<img src= <?php $theme ?> . "/images/logo.png"/>
on 2021...
Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme's top-level directory (where the style.css file is )
and that's all you need to do.

Categories