ThemeShaper Forums » Thematic

[closed]

problem adding post custom fields to custom loop

(5 posts)
  • Started 1 year ago by candregg
  • Latest reply from helgatheviking
  • This topic is resolved
  1. First, many thanks to HelgatheViking for stepping in to solve a tricky custom loop problem for this project.

    I am now trying to add three bits of custom field data to this custom loop only when they are available (in event category).

    The code below shows the new loop with my revisions included between the //Begin caa revisions and // END caa Revisions markers. The addition DOES successfully call the meta data and display it properly*, EXCEPT that it then gets caught up in the post count and so multiplies for each post. See http://seacliffmm.com/prod/indigest/admin/?cat=2213 (Events category page) for demo.

    What am I missing in order to get the custom field data for each post to display only beneath its own post-thumbnail and not multiply under under other posts' post thumbnails?

    /*
     * LOOPS
     */
    
    //default loop
    function kia_default_loop(){
    
    	global $options, $blog_id;
    
    	if($options) foreach ($options as $value) {
    	    if (get_option( $value['id'] ) === FALSE) {
    	        $$value['id'] = $value['std'];
    	    } else {
    	    	if (THEMATIC_MB)
    	    	{
    	        	$$value['id'] = get_option($blog_id,  $value['id'] );
    	    	}
    	    	else
    	    	{
    	        	$$value['id'] = get_option( $value['id'] );
    	    	}
    	    }
    	}
    
    	/* Count the number of posts so we can insert a widgetized area */ $count = 1; $column = 1;
    	while ( have_posts() ) : the_post();
    
    		$counter++; 
    
    		thematic_abovepost(); ?>
    
    			<div class="column <?php if ($counter == 1) { echo 'one'; $clear=false; } else { echo 'two'; $counter = 0; $clear=true;} ?>">
    
    			<div id="post-<?php the_ID();?>" <?php post_class();?> >
    
    				<?php 
    
    				$category = get_the_category();
    				if ($category) {
    					$catlink = '<a class="cat-link" href="' . get_category_link( $category[0]->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ';
    				} 
    
    				?>
    
    				<div class="entry-thumb">
    
    				<?php if(has_post_thumbnail()) {
    						the_post_thumbnail('homepage-thumb');
    					} else {
    						echo '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" ><img class="attachment-300x150 wp-post-image" src="' . get_stylesheet_directory_uri(). '/images/featured-image.png"/></a>';
    					}
    					echo $catlink;
    					?>
    				</div><!--.entry-thumb-->
    
    <?php // Begin caa Revisions  
    
       global $post;
       $eventdate = get_post_meta($post->ID , 'event-date', true);
       $eventtime = get_post_meta($post->ID , 'event-time', true);
       $eventprice = get_post_meta($post->ID , 'event-price', true);
    
    ?>
    
    				<div class="eventdetails">
    
    				<?php
       if($eventdate && $eventtime){
         $event .= '<p><strong>'.$eventdate.' | '.$eventtime.' | '.$eventprice.' </strong></p>';
    	 }
    					echo $event;
    
    					?>
    				</div><!--.eventdetails-->
    
    <?php // END caa Revisions  ?>
    
    				<?php echo thematic_postheader(); ?>
    
    				<div class="entry-content">
    
    				<?php
    					the_excerpt();
    					//echo '<a class="read-more" href="' . get_permalink( get_the_ID() ) . '" title="' . sprintf( __( "Permalink to %s" ), get_the_title() ) . '" ' . '>' . __('more').'&nbsp;></a> ';
    					?>
    
    				<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    				</div><!-- .entry-content -->
    				<?php //thematic_postfooter(); ?>
    			</div><!-- #post -->
    			</div><!-- .column -->
    
    		<?php 
    
    			thematic_belowpost();
    
    			comments_template();
    
    			if($clear) {
    				echo '<div class="clear"></div>';
    			}
    	endwhile;
    }

    * I was so proud of myself getting this to work this far--and then I saw the multiple displays.

    Posted 1 year ago #
  2. i'm not sure i see what you mean about things repeating. sidenote, i want to encourage you in the future to start posting support requests at the new site http://thematictheme.com/forums

    here's my first suggestion

    <?php // Begin caa Revisions  
    
    	if(in_category('events')){
    
       $eventdate = get_post_meta(get_the_ID(), 'event-date', true);
       $eventtime = get_post_meta(get_the_ID() , 'event-time', true);
       $eventprice = get_post_meta(get_the_ID() , 'event-price', true);
    
       <?php
       if($eventdate && $eventtime){ ?>
    
    		<div class="eventdetails">
    
    			<?php
    				echo '<strong>'.$eventdate.' | '.$eventtime.' | '.$eventprice.' </strong>
    ';
    			?>
    		</div><!--.eventdetails-->
    
    <?php }
       }
    // END caa Revisions  ?>
    Posted 1 year ago #
  3. Thanks I will bookmark the new forum location and change my bookmark.

    FYI: for an example, see http://seacliffmm.com/prod/indigest/admin/?cat=2213. Notice that under the first post, the meta-data displays as

    August 09, 2012 | 7pm | Free

    Under the second post (right column) it displays as:

    August 09, 2012 | 7pm | Free

    July 22, 2012 | 3:30pm | $5 all day

    Under the third and additional posts it displays as:

    August 09, 2012 | 7pm | Free

    July 22, 2012 | 3:30pm | $5 all day

    June 13, 2012 | 7pm | Free

    Yikes!

    Will go try your fix and see if it stops the madness.

    Thx.

    Posted 1 year ago #
  4. Yep, that fixed it. Will compare the two code bits, learn where I went wrong, and not make the same mistake again. Thx.

    Posted 1 year ago #
  5. not sure why

    $post->ID wouldn't work the same as get_the_ID(), but i'm glad that worked.

    Posted 1 year ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.