How to replace all attachment links in post with media file link - wordpress

I've been breaking my head over this for a few days but I yet have to find a proper solution. I'm working on a Wordpress site, where all images inside posts are linking to the corresponding attachment pages. I want to use a lightbox but obviously this would require changing all the links back to the media files directly (e.g. xyz.jpg).
The site has a significant number of posts and images so it would be impossible to do this manually.
Does anyone know of a plugin or other solution that would simply replace - in bulk - all of the image links to link to the media file, instead of the attachment page?

Here is one answer that, although jQuery-based, did the trick, and is much quicker than and safer than a PHP-script to go through the whole DB. The drawback is that it will link to the resized image url instead of the full image url. There's probably a way to catch that with jQuery as well, but this was enough for my needs.
$("article.my-post-class a img").each( function(){
var src = $(this).attr("src");
$(this).parent("a").attr("href", src);
});

Related

How to add an HTML class to all image attachments on posts in Wordpress -- except homepage

Sorry for the length, my problem is very simple, but specific.
I'm building a wordpress site that automatically imports image galleries from a Tumblr account, then styles and displays them. The backend is finished, and all that I need now is have all images in posts be displayed as thumbnail sized links. They are not behaving well with the importer (I've tried 6), so I have to edit the HTML display (rather than the images as they are uploaded).
I have decided to do this by applying class="attachment-thumbnail size-thumbnail" on all images on the site (in HTML). I have tested this and they will open the proper gallery in a lightbox as necessary so long as they belong to those two classes.
I have a two part problem.
I do not know PHP past basic syntax, and while I can intuit most of what is happening I don't trust myself to edit Wordpress source code without understanding exactly what I am breaking.
From other answers I've learned that I should most likely edit the wp_insert_attachment() function in post.php under wp_includes/. I have found the function, but don't really know where to go from there, as it does not appear to be specific to image attachments. I don't want to throw any errors by assinging image classes to non-image attachments. How do I add those two classes (attachment-thumbnail and size-thumbnail) to all post images (and only images)?
There is a single exception to this rule. I want a large image on the homepage, and have it not be a link.
It seems like the way to handle this would be to allow page attachments to be handled normally, while attachments that are both images and attached to posts should trigger this:
if [attachment is an image AND is on a post, not a page]:
<img src="https://whatever">
becomes
<img src="https://whatever" class="attachment-thumbnail size-thumbnail">
tl; dnr: ^^ that's all I need to happen, in PHP, in the right file, in Wordpress ^^
Thanks!
So likely you will want to do it via php but instead you could do it with javascript ie jQuery:
<script>
$(function() {
$("body img").addClass("attachment-thumbnail size-thumbnail");
});
</script>
Put that on any page or site header and it will add the class to all images. You can modify the search filter to suit.
You might need to re-call your lightbox initialization code too, or put this before it gets called initially.

Magento catalog image change on hover

On the catalog/category page I would like images change when hover. Like clubmonaco.com I know how to do it on html/css but no idea on magento. Any help?
You could modify files in this directory:
app/design/frontend/base/default/template/catalog/product
for example (list/ and list.phtml)
or your template for example:
app/design/frontend/default/yourtemplate/template/directory with product files
CSS files you can find in:
skin/frontend/
You should also think, where the second image is stored. You can use "CSS-Sprites" for this case - a single image file, that contains both photos. The disadvantage is, that you have to customize every page, where magento shows product images.
Alternatively you have to define exact orders. First image is the front view, second image is always the back view.
The programming part is not really difficult. Look at
app/design/frontend/base/default/template/catalog/product/list.phtml
for the Catalog view. Path can vary, if you have a custom template. In the Magento backend there is a feature to show up the real path (system->configuration->development tools).
You can write your Javascript directly into the list.phtml. Magento also writes JS-code directly in the .phtml files. Of course it's not very pretty, but Magento is so complex; if other people work with the shop system, it will be easier to find.
Keep in mind, that the list.phtml contains two layouts: Grid and List View. Just if you do a change and wonder, why you can't see a change in the frontend ;-)

How to return the generated image by phpThumb and not the original one with code appended?

I'm generating images through phpThumb on my Wordpress based website using Magic Fields 2 but I'm having problems posting those images to We Heart It and other websites since they don't recognize it as an image due to all the code appended.
Therefore I was wondering if there's a way to make phpThumb return the actual generated image thumbnail link instead of the original link with all the code appended like:
http://www.mywebsite.com/wp-content/themes/basetheme/phpThumb/phpThumb.php?src=http://www.mywebsite.com/wp-content/files_mf/1331856830IMG_0286.jpg&w=364&h=200&zc=1&q=95
Is there any way to achieve this?
http://ailoo.net/2008/07/wordpress-plugin-autothumb-phpthumb/ <-- I'm using this plugin for the same! :)

Wordpress image name same as page

Friends, i'm stuccoed with images in wordpress - please, help me understand where search for solution.
If you create webpage - www.wordpress.local/page1/01-0001 and you upload an image 01-0001 on that page, you can see, that when you'll visit www.wordpress.local/page1/01-0001, you'll see the page with image, not the page, that you created with text and images.
Any ideas how to solve it ?
PS Not renaming images :)
When you use the WordPress-uploader, the images are stored in /wp-content/uploads/, and WordPress takes care of using filenames that aren't already in use.
If you upload an image, e.g. via FTP, that has the same name as a WordPress-page, the server has to decide what it should serve; either the WordPress-page or the image. One URL = one file served.
In your case, the server decides for the image. You could of course change this configuration; but in all cases, one of the two files won't be accessible.
If you want to make both files accessible, you either need to rename the image or the WordPress-page.

How to display image into each recent post in drupal front page?

I am very new to drupal. As I have seen many of drupal free theme can show image in the recent post on the first page of drupal
I tried searching some ways to do but seem my keyword search was mismatched.
If you don't want to install any modules, you can simply use a standard HTML <img> tag to put an image in your node body (make sure your selected Input Format allows for the use of that tag). You can then use FTP to upload the linked images to your /sites/default/files directory.
The modules mentioned by Nikit (especially IMCE) can ease this process greatly. A the very minimum, IMCE allows you to upload files to your server without using FTP and adds a handy "insert image" link after your "body" input fields. Clicking that link uploads your image and then generates the <img> code for you.
You can simply style it in node body (wysiwyg + imce can help to quickly upload image and style it).
But recommend to you use image or cck + imagefield, and theme it via node-{CONTENTTYPE}.tpl.php
Little help here: http://www.hankpalan.com/blog/drupal-themes/theming-node-drupalthe-easy-way
But recommend to learn theming in drupal.
If you don't want to use HTML or change any PHP files then use the admin console.
http://drupal.org/node/1047760

Resources