Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Thanks to Rafael Marques I have a list of Products and Categories organized based on different created categories. I also have 5 different Custom Page Templates. Now I would like to display the products images (Only Images, because this is just an image gallery) in each of the pages. The Page temlate looks like:

<?php 
/**
Template Name: Gallery Art
*/
?>
<?php  get_header();?>
<div id="scrool" class="clearfix">
<div class="gal item"><a class="group4" href="img/gallery/Beauty/Beauty 1.jpg"><img  src="img/gallery/Beauty/gal/Beauty 1.jpg" alt="Ghazal Photo" width="231" height="149" />   </a></div>
</div>
<?php get_footer(); ?>

can you please let me know how I can do this based on Categories? For Example let say I have a Page called Art and powered based on Art_Page template.Now how I can add all images(products) to only this template which categorized under artCat?

Thanks

share|improve this question
    
How do you add the images to a page? Image gallery or featured images? –  Grávuj Miklós Henrich Jan 27 '13 at 21:34
    
I think it is better to be Image Gallery.Can you please let me know what is the different between them? –  Behseini Jan 27 '13 at 21:52
    
Let's focus on your main question please. Different questions you can open separated. –  Grávuj Miklós Henrich Jan 27 '13 at 22:12
add comment

1 Answer

In your functions.php

function show_all_thumbs() {
    global $post;
    $post = get_post($post);
    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent);
    if($images) {
        foreach( $images as $imageID => $imagePost ){
            unset($the_b_img);
            $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
            $thumblist .= '<a href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';
        }
    }
    return $thumblist;
}

In your page template file:

$loop = new WP_Query(
    array(
        'post_type'         => 'demo', // or whatever is called your custom post type
        'cat'               => 5, // or whatever is the "id" for your custom post type category
        'posts_per_page'    => 10
    )
);
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); 
    echo show_all_thumbs();
endwhile;
endif;

Let us know please.

For different/extra questions which have nothing to do with this topic, please ask them separated, starting a new questions thread.

Example for Featured Image version:

$loop = new WP_Query(
    array(
        'post_type'         => 'demo', // or whatever is called your custom post type
        'cat'               => 5, // or whatever is the "id" for your custom post type category
        'posts_per_page'    => 10
    )
);
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); 
    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
} 
endwhile;
endif;
share|improve this answer
    
Hi GRÁVUJ, Thanks for your help but I am not getting any images when I load the page.Can we do this through Feature Image? –  Behseini Jan 29 '13 at 15:00
    
yes, updated answer with another example code –  Grávuj Miklós Henrich Jan 29 '13 at 18:16
    
Sorry man! but this is still not working! I followed every thing but I do not know why is not working JUST empty page! btway thanks for your help and comments! –  Behseini Jan 29 '13 at 23:54
    
have you checked the parameters? are they correct. in the above examples they have only example purpose. i can't know what do you have in your dev environment. –  Grávuj Miklós Henrich Jan 30 '13 at 9:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.