Support » Themes and Templates » Return only photos

  • I’m looking for a way to have a category.php file for a specific category that returns only the photos in the posts, but still has the title to each post so you can click through and read the post. Help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You need to create a if statement in your category.php that does this for the specific category. Lets say you wanted to check if category 3 is being shown

    <?php if(is_category(3) ) { ?>

    Then you could add the photos as custom fields when writing the post and retrieve them in your template like this:

    <img src="<?php echo get_post_meta($post->ID, "custom-field-key", true); ?>" alt="<?php the_title(); ?>" />

    Then close the if statement

    <?php } ?>

    This will do the above for only category with the ID 3.

    Hmmm…is there a way to do it so that I wouldn’t have to go back and edit 4 years of posts? Is there a way to use the img tag alone to identify it?

    Try “Get the Image” plug-in. It will do the work.

    OK, this seems to be getting me in the right direction, however, I’m hitting one roadblock.

    In the readme it says “You might want to make the script grab the second attached image to a post. You can do that with this code: “

    What if I want it to pull ALL photos from a post?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Return only photos’ is closed to new replies.