Why did the logo not loading even the direct access working? - php

I have one template & i used base_url() to load the logo. In source the path can be accessible but the logo is not loading into the webpage ?
<a href="index.html" class="logo">
<img src="<?php echo base_url('assets/frontend/img/logos/logo.png'); ?>" alt="logo">
</a>
When i use without logo class its working
<img src="<?php echo base_url('assets/frontend/img/logos/logo.png'); ?>" alt="logo">
How i can load the logo within logo class ?

Related

Image not showing when using PHP to link to SRC

Trying to use php to link to an image in a different folder than the file I am currently in but the image isn't showing.
Here's the path file:
<?php
if (!defined("ROOT_PATH")) define ("ROOT_PATH", realpath(dirname(__FILE__)));
if (!defined("BASE_URL")) define ("BASE_URL", "http://localhost/stnresp");
?>
Here's the code I am using at the moment:
<div class="logo-image">
<img class="header-logo" src="<?php echo ROOT_PATH . '/assets/images/stn-logo-cropped.png'; ?>" alt="">
</div>
I can't understand why the root path isn't taking the link to the root directory and then through to the image? What am I missing?
Thanks
realpath defines the physical path of the file, instead the src attribute of the image needs url path.
In your case you have to use BASE_URL instead of ROOT_PATH:
<div class="logo-image">
<img class="header-logo" src="<?php echo BASE_URL . '/assets/images/stn-logo-cropped.png'; ?>" alt="">
</div>

Wordpress images don't get displayed

I started to learn Wordpress and I'm making my own theme. Within the design I have some images that are supposed to show up... but they don't.
I was using this code:
<div class="col-xs-4">
<img src="images/html_brand.jpg" class="img-responsive">
</div>
and then I found I should use php to link to my image:
<div class="col-xs-4">
<a href="#">
<img src="<?php bloginfo('stylesheet_directory'); ?>html_brand.jpg"
class="img-responsive">
</a>
</div>
But the problem is, the image still doesn't get displayed. And yes I did upload them to my web server. I have them in the directory of my theme: mythemename/images/html_brand.jpg
If you use bloginfo() to output your theme path, you need to add another /, followed by the remaining path to your image. Based on where you've placed your image, this should work:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/html_brand.jpg" class="img-responsive">
However, bloginfo() ultimately relies on get_template_directory_uri() to work, so you might as well just use that:
<img src="<?php echo get_template_directory_uri(); ?>/images/html_brand.jpg" class="img-responsive">
Slight Correction:
bloginfo() with the specific argument of stylesheet_directory actually relies on get_stylesheet_directory_uri() to function -- get_template_directory_uri() like I originally said.
https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/general-template.php#L439

image click redirecting to a URL, and then clicking on an image of the new URL to go back to main page

I am doing a photo gallery with php, and my main page is a gallery with all thumbnail images. If you click on any thumbnail, it will link to another page with the original size image (like google images does). I do that with an hyperlink that contains an image inside :
<a href='".$row['image']."' class='image' title='".$row['title']."'>"."<img src=".$row['thumb']." class='thumb'/> </a>
Then if the user is now in the redirected page showing the big image selected, how can I do it so that if the user clicks on top of the big size image then it will be redirected to the main page with all the thumbnails?
<a href="<?php echo $row['image'];?>"class='image' title="<?php echo $row['title'];?>">
<img src="<?php echo ['thumb'];?>" class='thumb'/>
</a>
If you are able to link to a detail page using <a href, why are you not able to do the same from the detail page?
considering you are on listing page, say listing.php and images are listed from database. You can loop through the images as given below.
<a href="detail-image.php?id=<?php echo $image_from_database['id'];?>" class='image' title="image title">
<img src="<?php echo $image_from_database['thumb'];?>" class='large'/>
</a>
So, on clicking you will be redirected to detail-image.php where you can get the id using PHP $_GET/$_REQUEST
and then fetch the big image from database and show it. There you can do same to link to the listing page
<a href="listing.php" class='image' title="image title">
<img src="<?php echo $image_from_database['large_image'];?>" class='thumb'/>
</a>
Look I don't know exactly what's the problem,
but I think there wrong in your code,
must be like it,
<a href="<?php echo $row['image'];?>"class='image' title="<?php echo $row['title'];?>">
<img src="<?php echo ['thumb'];?>" class='thumb'/>
</a>
!! The page must be "Something.php"

PHP Include Directory

I am calling socialmedia.php from every page on my website to display a little "Social Media" div where people can visit my social media pages.
I am calling this using <?php include './socialmedia.php' ?> or <?php include './socialmedia.php' ?> depending on what directory I am in.
In my socialmedia.php file I have the following code.
<a href="http://twitter.com/kinghenryharris" target="_blank">
<img class="socialMedia" src="../images/twitter_logo.png" alt="Twitter" width="40px" height="40px"></br>
</a>
<a href="http://facebook.com/kinghenryharris" target="_blank">
<img class="socialMedia" src="../images/facebook_logo.png" alt="Facebook" width="40px" height="40px"></br>
</a>
<a href="http://youtube.com/mrgorillalogic" target="_blank">
<img class="socialMedia" src="../images/youtube_logo.png" alt="Youtube" width="40px" height="40px"></br>
</a>
Is it bad practice if I am in the home directory to do ../images/youtube_logo.png
When calling it from www.example.com/page.php does it matter that I am going up two directories with ../images/youtube_logo.png`
It seems to work but I am wondering if this is wrong or I should change it so if I am in the home directory do ./images/youtube_logo.png or should I just leave it the same?
-Henry

How can I get the image url in a Wordpress theme? [duplicate]

This question already has an answer here:
How can I get the image url in WordPress?
(1 answer)
Closed 2 years ago.
I am developing a theme for wordpress. And I have many images in 'images' folder. But when I take the page in browser it is not comming.
My code is
index.php
<ul>
<li><img src="images/mindset.jpg" width="145" height="32" /></li>
Is there any function for getting the image path in wordpress ?
src="<?php echo base_url()?>your_theme_dir/image_dir/img.ext"
As well
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
get_template_directory_uri();
This function will help you retrieve theme directory URI, and can be used with your images, your example below:
<img src="<?php echo get_template_directory_uri(); ?>/images/mindset.jpg" />
I had to use Stylesheet directory to work for me.
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/image.png">
You need to use
<?php bloginfo('template_directory'); ?>
It returns the directory of the current WordPress theme.
Now for example, if your theme has some image named example.jpg inside some folder name subfolder folder in the images folder.
themes
|-> your theme
|-> images
|->subfolder
|-> examples.jpg
You access it like this
<img class="article-image" src="<?php bloginfo('template_directory'); ?> /images/subfolder/example.jpg" border="0" alt="">
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext" worked for me for wordpress 3.6 i used it to get header logo using as
<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg">
If you are developing a child theme you can use:
<img src="<?php echo get_template_directory_uri(); ?>-child/images/example.png" />
get_template_directory_uri() will return url to your currently active theme (parent theme), then you add -child/, then add path to your image (the example above assumes your image is at <child-theme-directory>/images/example.png)
I strongly recommend the following:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img-folder/your_image.jpg">
It works for almost any file you want to add to your wordpress project, be it image or CSS.
If your img folder is inside your theme folder, just follow the example below:
<img src="<?php echo get_theme_file_uri(); ?>/img/yourimagename.jpg" class="story-img" alt="your alt text">
You asked of Function but there is an easier way too. When you will upload the image, copy it's URL which is at the top right part of the window (View Screenshot) and paste it in the src='[link you copied]'. Hope this will help if someone is looking for similar problem.

Categories