taxonomy.php doesn't display images from "../image/" folder - wordpress

i have some images loading in the header (header.php) from the location "../images/"
code is
<div class="header">
<img src="../images/headerimg.gif" alt=""/>
</div>
while the pages and custom post type load the image correctly from the location ..
the taxonomy.php doesn't load the image at all instead shows the cross sign which image is there but not loaded
plz help

In wordpress, you should never use such relative paths.
You should use one of the Built-in path functions , like get_template_directory_uri()
<?php echo get_template_directory_uri(); ?>/images/headerimg.gif">
or in the event you want to be included or ovverriden by child theme use get_stylesheet_directory_uri()
All this of course assumes that the images are in a sub-folder called images under the main theme folder. ( which is how it is supposed to be )
In case that the image is an Uploaded image , it should be referenced by the ID or the URL that is supplied from the upload . Even in the case you do not want to do so for some ( probably wrong ) reason , you should then also use wp functions like for example wp_upload_dir()

Related

How to remove hardcoded domain name from WordPress links?

Wordpress loads all assets and links with an absolute URL including the domain name (e.g. <img src="https://example.com/cat.png">).
How to NOT include the domain name?
I tried editing the WP_CONTENT_URL and updating WP_SITEURL/WP_HOME with no success.
Is there a simple way of doing that?
You can do that by simply WordPress theme URL function get_template_directory_uri(). See the below link.
https://developer.wordpress.org/reference/functions/get_template_directory_uri/
It will give a full path to the WordPress theme. If your image path is like this
\wp-content\themes\your-theme\assets\images\image.jpg
then you can get that image path like below.
<img src="<?php echo get_template_directory_uri() . '/assets/images/image.jpg'; ?>">

Change the Path of wordpress featured image

I am trying to change the current path obtained bywp_get_attachment_url(get_post_thumbnail_id)
Now I get the uri as http://localhost/velocity/wordpress/wp-content/themes/velocity/images/pic01.jpg.
but I want to change the uri as http://newhost/velocity/wordpress/wp-content/themes/velocity/images/pic01.jpg
any idea?
The image you're referring to isn't an attachment image...it's a theme asset.
If you're properly including this in your template, changing hosts won't be a problem and the URL will automatically update. The following is an example of how you could be including the src in your template, using get_stylesheet_directory_uri():
<img src="<?php echo get_stylesheet_directory_uri() . '/images/pic01.jpg'; ?>">

Images not showing up on WordPress custom theme

I have a custom WordPress theme installed and my images are referenced as such:
index.php:
<img src="images/newlogo.png" height="110px" width="400px"/>
My images folder is relative to my index.php from which I have included the above code.
My images are not showing when I render the webpage in a browser, it is showing the default image not found thumb instead.
Image filepath:
wp-content/themes/my-theme/images/newlogo.png
Homepage (index.php) filepath:
wp-content/themes/my-theme/index.php
Your index.php is a template that will be loaded by WordPress's main entry point (at /index.php) and the code behind it; as such its URL won't be ...wp-content/themes/my-theme/index.php. You should use the WordPress method get_stylesheet_directory_uri() to find your theme's directory from any of your theme template files.
For example:
<img src="<?php echo get_stylesheet_directory_uri() ?>/images/newlogo.png" height="110px" width="400px"/>
Basically, any relative paths to images from a web page are considered as relative to that web page's URL. However, with WordPress templates, you can't know for sure what the actual URL will be -- your index.php template might (probably will) be used for many different pages on your site, at many different URLs. It could be used at the top level for a page at /about, and also for an entry at /blog/2014/01/05/typical-blog-post, for example.
WordPress handles both building the URLs and loading your template file into them appropriately. But this means that you can't depend on the URL of the template you're writing being a constant. Instead, WordPress provides a series of functions, like get_stylesheet_directory_uri(), to let you grab and output the correct URI to your stylesheet files as necessary.

how to assign image dynamically in wordpress post

I am developing one wordpress site. I have made one post in it. Now I want to assign image in that post. For this, I have uploaded one image in media and attach that image to my post.
but how can I assign that uploaded image in my post? do I need to give path manually? or I can give dynamic path so that even if I upload this site on server or change main folder name, path gets changed automatically..
any help will be appreciated..
thank you
You should consider using Post Thumbnails (also known as Featured Images) in your posts. To do this, all you need to do is add the following to your functions.php file:
add_theme_support('post-thumbnails');
This will add a control in your Post Editor to add an image by either Uploading it or setting the URL, effectively "attaching" your image to your post in the way your looking for. To display the image in your template:
<?php
if(have_posts()) : while(have_posts()) : the_post();
if(has_post_thumbnail())
echo '<div class="post_thumb">'.get_the_post_thumbnail().'</div>';
?>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
As for changing folder names, paths, etc. you need to be careful with that approach. Remember that you're giving a path to an asset. The server doesn't know what YOU want, only what your code is requesting. If you expect to be changing paths to your assets around quite a bit, then you can always forgo Post Thumbnails in favor of clever naming conventions. Something like this:
<?php
if(have_posts()) : while(have_posts()) : the_post();
$imgPath = get_bloginfo('stylesheet_directory').'/images/featured_'.$post->post_name.'.jpg';
?>
<div class="post_thumb"><img src="<?php echo $imgPath; ?>" /></div>
<div class="post_content"><?php the_content(); ?></div>
<?php
endwhile;endif;
?>
This looks for an image in your Theme Directory's images folder that is named featured_{post_slug}.jpg
The benefits to this approach is that Wordpress will always know where your theme folder is, regardless of URL changes. As long as you have an images folder in your theme directory, Wordpress will know where to look.
The drawback is that this code specifically doesn't first check for the EXISTENCE of the image before displaying it, which could lead to broken images if they aren't named properly or don't exist at all. This approach also requires the use of one file extension
A last option for you is to consider using Custom Fields to define paths to images. The benefit is that this does not require you to actually upload images to your server. However, this approach is still the least dynamic out of all of your options, and will likely break if paths to assets are changed.
Use whichever tool you feel is best for the job. Hope this helps!

drupal cck image_field and imagecache

I am having trouble getting imagecache to generate a thumbnail based on a preset I have created named 'thumbnail'. I have an cck image_field and a custom node view. The code I am using to output my images is:
<?php foreach($node->field_comm_gallery as $galleryItem) { ?>
<?php print theme('imagecache', 'thumbnail', $galleryItem['filepath'], $alt = '', ''); ?>
<?php } ?>
The output I get from the following is:
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_0.jpg"/>
<img class="imagecache imagecache-thumbnail" title="" alt="" src="http://127.0.0.1/sites/default/files/imagecache/thumbnail/cedimages/3388564188_4427beac12_b_2.jpg"/>
Everything looks correct but those files do not exist in that folder.
My question: Is the print theme(..) call supposed to generate the thumbnail on the fly when it is called, or is the thumbnail generated when a node is created/updated?
I am using the GD Image processer and receive no errors.
The node field value has within it the display value already generated. So using theme function is not needed. But the file should be created regardless. It looks like the problem is the permission to either Drupals temp folder or the files folder. Take a look at those in the files settings.
Thanks for the help. It actually turned out to be this bug (http://drupal.org/node/540486#comment-2356560)
I had to remove the & from the function parameters in imageapi.module
function imageapi_gd_image_resize(&$image, $width, $height)
No clue why, but it seems to break when using php 5.x

Resources