I am building my first WordPress theme. I am having trouble with media attachment. When I upload and image, and insert it into the post, it shows the image. If I link it to “Media File” then it also takes me to the file when clicked upon. But if I try to link to “attachment-page” it does not show the image. I am NOT using a custom ‘attachment.php’ instead I’m only using the default ‘single.php’. Here is the code of single.php:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div>
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
</div>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
</div>
<?php // comments_template(); ?>
<?php endwhile; endif; ?>
</div> <!--main-content Ends-->
@Zeeshan
Your single.php document does not appear to have the proper PHP code to output the attachments. Try adding the following code within the loop, wherever you’d like the attachment content to show up:
This code works with the latest 3.x CORE but also has a fallback for older versions.
If provided,
the_content()
function outputs the media description.Attachment pages range from using simply attachment.php file to almost a dozen other template files.
http://codex.wordpress.org/Template_Hierarchy#Attachment_display
Attachment display
Template file used to render a single attachment (attachment post-type) page.
application.php). For text/plain, in order:
You can have mime type specific templates for attachments. For example, over at my blog I have a snapshot of a JavaScript Meetup using the mime type specific image.php attachment template that handles image attachments.
So if your dealing with images, then I suggest you create an image.php file and drop that into your themes folder and get to work.
Your question is not clear enough!!
Well when you upload insert an image in to a post it automatically links to that image some thing like this:
But you can give your custom link by editing the default link!
I would recommend to add the jetpack plugin and use some of its build-in functionalities for handling images! Not only they are going to solve your problem, but you will have more options like carousel or mosaic view.