Don't like ads? PRO users don't see any ads ;-)
Guest

get_children not working in category

By: a guest on Feb 6th, 2011  |  syntax: None  |  size: 5.91 KB  |  hits: 413  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Category Template
  4.  */
  5.  
  6. get_header(); // Loads the header.php template. ?>
  7.  
  8.         <?php do_atomic( 'before_content' ); // prototype_before_content ?>
  9.  
  10.         <div id="content">
  11.  
  12.                 <?php do_atomic( 'open_content' ); // prototype_open_content ?>
  13.  
  14.                 <div class="hfeed">
  15.  
  16.                         <?php if ( have_posts() ) : ?>
  17.  
  18.                                 <?php while ( have_posts() ) : the_post(); ?>
  19.                
  20.  
  21.                                         <?php do_atomic( 'before_entry' ); // prototype_before_entry ?>
  22.  
  23.                                         <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
  24.  
  25.                                                 <?php do_atomic( 'open_entry' ); // prototype_open_entry ?>
  26.  
  27.                                                 <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
  28.                                                                
  29.                                                 <div class="photos">
  30.                                                         <?php get_main_image(); ?>
  31.                                         <div class="thumbs">
  32.                                                        
  33.                             <!-- Display the Post's Remaining Image Attachments. -->
  34.                                                         <?php get_thumbs(); ?>
  35.                                                        
  36.                             </div></div>
  37.  
  38.                                                 <div class="entry-content">
  39.                                                         <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', hybrid_get_textdomain() ) ); ?>
  40.                                                         <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', hybrid_get_textdomain() ), 'after' => '</p>' ) ); ?>
  41.                                                 </div><!-- .entry-content -->
  42.  
  43.                                                 <?php do_atomic( 'close_entry' ); // prototype_close_entry ?>
  44.  
  45.                                         </div><!-- .hentry -->
  46.  
  47.                                         <?php do_atomic( 'after_entry' ); // prototype_after_entry ?>
  48.  
  49.                                         <?php get_sidebar( 'after-singular' ); // Loads the sidebar-after-singular.php template. ?>
  50.  
  51.                                         <?php do_atomic( 'after_singular' ); // prototype_after_singular ?>
  52.  
  53.                                         <?php comments_template( '/comments.php', true ); // Loads the comments.php template. ?>
  54.  
  55.                                 <?php endwhile; ?>
  56.  
  57.                         <?php endif; ?>
  58.  
  59.                 </div><!-- .hfeed -->
  60.  
  61.                 <?php do_atomic( 'close_content' ); // prototype_close_content ?>
  62.  
  63.                 <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>
  64.  
  65.         </div><!-- #content -->
  66.  
  67.         <?php do_atomic( 'after_content' ); // prototype_after_content ?>
  68.  
  69. <?php get_footer(); // Loads the footer.php template. ?>
  70.  
  71.  
  72.  
  73. <?php
  74. /**
  75.  * Single-Portfolio Template
  76.  */
  77.  
  78. get_header(); // Loads the header.php template. ?>
  79.  
  80.         <?php do_atomic( 'before_content' ); // prototype_before_content ?>
  81.  
  82.         <div id="content">
  83.  
  84.                 <?php do_atomic( 'open_content' ); // prototype_open_content ?>
  85.  
  86.                 <div class="hfeed">
  87.  
  88.                         <?php if ( have_posts() ) : ?>
  89.  
  90.                                 <?php while ( have_posts() ) : the_post(); ?>
  91.                
  92.  
  93.                                         <?php do_atomic( 'before_entry' ); // prototype_before_entry ?>
  94.  
  95.                                         <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
  96.  
  97.                                                 <?php do_atomic( 'open_entry' ); // prototype_open_entry ?>
  98.                                
  99.                                                 <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
  100.                        
  101.                                                         <div class="photos">
  102.                                                         <?php get_main_image(); ?>
  103.                                         <div class="thumbs">
  104.                                                        
  105.                             <!-- Display the Post's Remaining Image Attachments. -->
  106.                                                         <?php get_thumbs(); ?>
  107.                                                        
  108.                             </div></div>
  109.  
  110.                         <div class="entry-content">
  111.                                 <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', hybrid_get_textdomain() ) ); ?>
  112.                                                         <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', hybrid_get_textdomain() ), 'after' => '</p>' ) ); ?>
  113.                                                 </div><!-- .entry-content -->
  114.  
  115.                                                 <?php do_atomic( 'close_entry' ); // prototype_close_entry ?>
  116.  
  117.                                         </div><!-- .hentry -->
  118.  
  119.                                         <?php do_atomic( 'after_entry' ); // prototype_after_entry ?>
  120.  
  121.                                         <?php get_sidebar( 'after-singular' ); // Loads the sidebar-after-singular.php template. ?>
  122.  
  123.                                         <?php do_atomic( 'after_singular' ); // prototype_after_singular ?>
  124.  
  125.                                         <?php comments_template( '/comments.php', true ); // Loads the comments.php template. ?>
  126.  
  127.                                 <?php endwhile; ?>
  128.  
  129.                         <?php endif; ?>
  130.  
  131.                 </div><!-- .hfeed -->
  132.  
  133.                 <?php do_atomic( 'close_content' ); // prototype_close_content ?>
  134.  
  135.                 <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>
  136.  
  137.         </div><!-- #content -->
  138.  
  139.         <?php do_atomic( 'after_content' ); // prototype_after_content ?>
  140.  
  141. <?php get_footer(); // Loads the footer.php template. ?>
  142.  
  143. ///////////////////////////////////////////////////////////////////////////////////////////
  144. // The get_children() function call made in get_main_images() in functions.php
  145. ////////////////////////////////////////////////////////////////////////////////////////////
  146.  
  147. function get_main_image($size = 'large', $limit = '1', $offset = '0', $post) {
  148.  
  149.         $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
  150.        
  151.         if ($images) {
  152.                 $num_of_images = count($images);
  153.         if ($offset > 0) : $start = $offset--; else : $start = 0; endif;
  154.         if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif;
  155.  
  156.                 $i = 0;
  157.                 foreach ($images as $image) {
  158.                
  159.                         if ($start <= $i and $i < $stop) {
  160.                         $img_title = $image->post_title;   // title.
  161.                         $img_description = $image->post_content; // description.
  162.                         $img_caption = $image->post_excerpt; // caption.
  163.                         $img_url = wp_get_attachment_url($image->ID); // url of the full size image.
  164.                         $preview_array = image_downsize( $image->ID, $size );
  165.                         $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
  166.                        
  167.                         ?>
  168.            
  169.                         <a href="<?php echo $img_url; ?>" title="<?php echo $img_title; ?>" >
  170.                         <img id="photo" src="<?php echo $img_preview; ?>" alt="<?php echo $img_caption; ?>" title="<?php echo $img_title; ?>"></
  171.                        
  172.            
  173.                         <?
  174.                         // End custom image tag. Do not edit below here.
  175.                         ///////////////////////////////////////////////////////////
  176.  
  177.                         }
  178.                         $i++;
  179.                 }
  180.  
  181.         }
  182. }