Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Why Attachment Page Defaults to Article Page? WordPress

  • SOLVED

Hello Guys and Gals,

I have a problem...

Say I have a url:

http://www.yahoo.com/post1

And within this url are photos that are linked to their respective attachment pages. The reason for this is to create more pageviews for readers going through slideshows and such...that every pic would have his url with alt tags, etc. which helps out with SEO and things of that nature. The reader can go from one pic to the next by clicking some type of "next photo" button that is linked to the photo in its own respective page.

So for example the pics in post 1's url will look like this:

http://www.yahoo.com/post1/beyonce-pregnant
http://www.yahoo.com/post1/scarlett-naked
http://www.yahoo.com/post1/rip-mj
http://www.yahoo.com/post1/lovers-reunited

And et cetera...

The problem that I'm having is that when you click on the pic to take you to its url, it always go to http://www.yahoo.com/post1, no matter what pic I click, it takes you the main article where pics are displayed. It's almost as if the browser just refreshes the page.

I thought that there was an issue with my permalinks but they're working because all of my links work other these attachment links as far as I know.

To see an example of what I'm talking about, go here: http://theurbantwist.com/2011/09/14/nba-rookie-josh-selby-says-he-is-not-gay-but-curious/

I didn't do a full fledge photo gallery, but the pic in the post is an example of what's going on. You click the pic and it basically refreshes the page.

The reason I need this is because I'm working on customizing a gallery similar to this page:http://www.hellomagazine.com/music/gallery/200906261527/michael/jackson/gallery/1/

But I would need to get past this roadblock first unless anyone else has any suggestions?

Thanks

Answers (3)

2011-09-15

Ivaylo Draganov answers:

Hello Brennen,

Whether the "post url" option links to the attachment page correctly depends on the current theme that you are using. There is something called the [[LINK href="http://codex.wordpress.org/Template_Hierarchy#Attachment_display"]]"Template Hierarchy"[[/LINK]] in WordPress - it determines which template WP loads when a certain content type is requested.

For image attachments WP first looks for a file named "image.php", then "attachment.php" and if these are not present it uses "single.php".

Some themes are set to redirect to the parent post for image attachment pages. Please check whether your theme contains a file "image.php" or "attachment.php".

And I notice that on the particular example that you gave the attachment has the same slug as the post - maybe that's causing the reload.


Brennen Jones comments:

That's what I thought initially but I checked and have an attachment.php page and I then created new post and backdated it just so it doesn't show up in recent rss feeds.

Here it is: http://theurbantwist.com/2005/09/15/test/

And notice how the slug is different than the post this time and we're still having the same problem.


Brennen Jones comments:

Another thing I did was reinstall wordpress and activated default theme, but seems like that doesn't do trick either


Ivaylo Draganov comments:

<blockquote>Another thing I did was reinstall wordpress and activated default theme, but seems like that doesn't do trick either</blockquote>

That's odd. Did you try disabling all your plugins?


Brennen Jones comments:

It's always something simple, isn't it? LOL

I deactivated plugins and reactivated one by one and found out it was my SEO plugin that was messing things up.

http://wordpress.org/extend/plugins/wordpress-seo/

I should've picked up on this. I feel stupid, lol. But I guess that's what this site is for.

I really like this SEO plugin but now may have to find another alternative. I liked this one better than the All-in-One SEO pack.

Do you have any suggestions?


Brennen Jones comments:

Quick note: I found an option within that SEO plugin that I had to check to make things work.

Also, how do I pick winner? It seems that they've changed some things around since last time I was on here. I voted but it didn't select you as winner.

2011-09-15

Milan Petrovic answers:

When you edit images to add to posts, there is a setting for the URL where the click will point to, and it is called 'Link URL'. You can set it to any url, post url or url to an image. There are 3 buttons to change this URL. You were setting this wrong to post url, you want to change it to image url. Problem is that you must change to all images you already added manually, there is no way to do it automatically. See attached image.


Brennen Jones comments:

According to Wordpress, the post url is supposed to bring up attachment page and it's not. It just refreshes the page.

The url to my source is found here:

http://codex.wordpress.org/Using_Image_and_File_Attachments

I need attachment page to show so from there I can customize it

2011-09-15

Luis Abarca answers:

Edit your images to point to the "file url" instead of "post url", you can also loop trough all the post attachments an show them as a gallery


$args = array( 'post_type' => 'attachment', 'post_parent' => $post->ID );

$attachments = get_posts( $args );

if ($attachments) {
foreach ( $attachments as $post ) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
$image = wp_get_attachment_image_src( $post->ID, 'medium' );
?>
<a href="<?php echo $image['url'] ?>"><img src="<?php echo $image['url'] ?>" /></a>
<?php
the_excerpt();
}
}
?>


Brennen Jones comments:

I think I understand...for some reason I had originially had it linked to file but was trying to set it up for that gallery example that I showed you. I feel like such a dummy, lol.

I thought that there was a way to link to the attachment file and that there was a general template for me to then customize to get it to that example I showed you.

Where does your code go in template files?


Luis Abarca comments:

In the single.php or wherever you need to show the gallery images


Brennen Jones comments:

Just to follow up, I've been in that example I gave you originally, I linked to "post url" which according to wordpress would bring up attachment page. I guess the main thing I'm asking is why isn't this attachment page showing up?

I think that's what I need.