fcarthy
Forum Replies Created
-
Forum: Hacks
In reply to: Taxonomy-related posts in single.phpHi, I tried both what you posted as well as the nullcore.nl link, but I get no results. This is what I’ve got going now using the nullcore.nl code:
function related_mess() { global $wp_query; $exclude = $wp_query->post->ID; $relation = get_the_term_list( $post->ID, 'tag',' ', ', ', '' ); if(!empty($relation)) { ?> <ul id="related-mess"> Gerelateerd: <?php $rmquery = new WP_query(array('clipping' => $relation, 'showposts' =>10, 'post__not_in' => array($exclude))); while ( $rmquery->have_posts()) : $rmquery->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; wp_reset_query(); ?> </ul> <?php } }and within the loop in my single.php file I have:
<?php related_mess(); ?>I have a custom post type of ‘clipping’ and a custom taxonomy of ‘tag’. I’m simply trying to retrieve related posts by ‘tag’. Another thing, each post may have more than one tag, not sure if this works with more than one tag…
I’ve tried interchanging the code in the new Query with both ‘tag’ and ‘clipping’ and they both gave me the same result…
What am I doing wrong?
Forum: Hacks
In reply to: Help with nested loops please!Hi Bryan, thanks for the tip.
I’ve decided to remove the nested loop for now. The way I was envisioning it it creates a bit of confusion for the user. Great idea in concept, but not in execution.
Forum: Hacks
In reply to: Help with nested loops please!Forum: Hacks
In reply to: Help with nested loops please!Hi Mark! Thank you! It’s working ALMOST perfectly. I really appreciate your time.
The UL small-posts is now randomizing correctly without affecting the second post, which is what I needed. The only problem that’s happening now is that the small-posts UL is embeded within the overall “post” class, so the four small posts show up within the boundaries of the post. I tried to modify the code a little, all I did was move up the closing div for the post class above the UL, but I still get the same result. How can I make the UL show up between the posts independent of the post class?
<?php get_header(); ?> <div id="content"> <?php // First query $my_query = new WP_Query; $my_query->query( array( 'post_type' => 'clipping' ) ); // If first query have posts if( $my_query->have_posts() ) : $count = 0; // While first query have posts while ($my_query->have_posts()) : $my_query->the_post(); // Setup vars $count++; $do_not_duplicate = $post->ID; $clipping_image = get_post_meta( $post->ID, 'clipping_image', true ); $subtitle = get_post_meta( $post->ID, 'subtitle', true ); $incr_number = get_post_meta( $post->ID,'incr_number',true); $terms_of_post = get_the_term_list( $post->ID, 'types', '','', '', '' ); ?> <div class="post" id="post-<?php the_ID(); ?>"><!-- start post --> <div class="entry-content"> <?php if( $clipping_image ) : ?><a href="<?php the_permalink(); ?>"><img src="<?php echo $clipping_image ?>"></a><?php endif; ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <?php if( $subtitle ) echo $subtitle; ?> <p><?php the_content('Read the rest of this entry »'); ?></p> <p class="category"><?php if( $incr_number ) echo "#$incr_number"; ?> Posted in <?php if( $terms_of_post ) echo $terms_of_post; ?></p> </div> </div> <!-- End post div --> <?php // If count is equal to 2 if( $count == 2 ) : // Second query $my_second_query = new WP_Query; $my_second_query->query( array( 'post_type' => 'clipping' , 'orderby' => 'rand' , 'posts_per_page' => '4' ) ); // If second query have posts if( $my_second_query->have_posts() ) : ?> <ul class="small-posts"> <?php // While second query have posts while( $my_second_query->have_posts() ) : $my_second_query->the_post(); // Setup vars $do_not_duplicate = $post->ID; $incr_number_two = get_post_meta( $post->ID, 'incr_number', true ); ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark"><?php image_attachment('clipping_image', 140, 140); ?></a> <?php if( $incr_number_two ) echo '<p class="small-post-number">'. "#$incr_number_two" . '</p>'; ?> </li> <?php // End second while have posts endwhile; ?> </ul> <?php // End if second query have posts endif; // End if count is equal to 2 endif; ?> <?php // End first while have posts endwhile; // End if first query have posts endif; ?> </div> <!-- end content --> <?php get_footer(); ?>Thanks again for your help!!
Forum: Hacks
In reply to: Display Images From Custom Post Field in Custom ColumnAny help?
Forum: Fixing WordPress
In reply to: Custom fields data disappears after a few mins?Thanks for the update jbucks, saved my life!
Forum: Fixing WordPress
In reply to: How to character limit for custom fields?got it to work. It was working this last time I tried, i just hadn’t noticed it… thanks for the code!
Forum: Fixing WordPress
In reply to: How to character limit for custom fields?I placed the code in my loop so that it pulls the custom field on every post like so:
<?php $trim_length = 5; //desired length of text to display $custom_field = 'drink description'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo rtrim(substr($value,0,$trim_length)); } ?>but no dice….
Forum: Fixing WordPress
In reply to: How to character limit for custom fields?any help is welcome!
Forum: Fixing WordPress
In reply to: Custom field limit?my apologies. I misunderstood the code. thanks for clarifying!
Forum: Fixing WordPress
In reply to: Custom field limit?That’s really weird. I have several custom fields, and none of them are affected.
Forum: Plugins
In reply to: Change post category after future post dateI just found wp_set_post_categories. Could I use something like this?
if ( abs(time()-get_the_time('U')) > (.35*86400) ) { wp_set_post_categories( $post_ID, 4 ); } }Forum: Fixing WordPress
In reply to: How to character limit for custom fields?Correction, this is how I placed my code:
$trim_length = 21; //desired length of text to display $custom_field = 'drink description'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo '<p>I want to use: ' . rtrim(substr($value,0,$trim_length)) . '...</p>'; }Forum: Fixing WordPress
In reply to: Custom field limit?I placed this function in my functions.php file but nothing happens… what am I doing wrong?
Forum: Fixing WordPress
In reply to: How to character limit for custom fields?Hi MichaelH,
I can’t seem the get this to work. When I put this in my functions.php file I got an error due to the <?php that’s at the beginning. I placed the code exactly like this to not get an error:
$trim_length = 21; //desired length of text to display $custom_field = 'your custom field key here'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo '<p>I want to use: ' . rtrim(substr($value,0,$trim_length)) . '...</p>'; }but it still doesn’t work.. why am I doing wrong?