Function to call either single post or category

If this is the same if/else, you can just combine into if ( is_category() || is_single() ). You don’t need to pass anything to is_category() or is_single() most of the time, unless you are looking for a category or post in particular.

Help Combine These Two PHP Codes

here: <?php if ( has_post_format( ‘image’ )) { ?> <a href=”https://wordpress.stackexchange.com/questions/21659/<?php the_permalink() ?>”> <?php $image = catch_that_image(); if( $image ) { ?> <img src=”<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $image; ?>&amp;h=240&amp;w=280″ class=”index” alt=”<?php the_title(); ?>” title=”<?php the_title(); ?>” /> <?php } ?> </a> <?php } ?>

A better code for no post format?

I’m not sure I understand. Do you just want to join all the if-statements together? If that’s the case you could use elseif, like so: <?php $format = get_post_format(); if ( false === $format ) { echo ‘This is a default post’; the_excerpt(); } elseif ( has_post_format( ‘video’ )) { ?> A VIDEO POST <?php … Read more

Custom forms with HTML

In theory, this should work just fine if you are putting the code directly into a theme file, and not into a post body or something. However, it is very dependent on your site’s setup. Here are some things to watch out for: Permalink structure: if using GET requests to process the form, test to … Read more

How can I sort the order of multiple custom field values in a custom post type?

the function the_meta() formats the data into an unordered list and you have no control over the order. Instead you should use get_post_custom() and echo out only the fields you want and in the order you want. change: <?php echo(the_meta()); ?> to : $post_custom = get_post_custom($post->ID); echo ‘<ul>’; echo ‘<li>’.$post_custom[‘Height’].'</li>’; echo ‘<li>’.$post_custom[‘Fueled_By’].'</li>’; echo ‘<li>’.$post_custom[‘Favorite_Quote’].'</li>’; echo … Read more

Query pulling a single post per month

Maybe a bit less hacky: $months = array(); while(….){ list($month, $year) = explode(“https://wordpress.stackexchange.com/”, get_the_date(‘n/y’)); // eg. 7/11 if(in_array($month, $months)) continue; // skip $months[] = $month; echo ‘<li><a href=”‘.get_month_link($month, $year).'”>’.get_the_date(‘F Y’).'</a></li>’; } If you’re only getting 6 posts and you don’t need pagination that I guess it’s OK to go this way. Otherwise you need to … Read more

WordPress time queries

WordPress tries to set PHP environment to UTC timezone. Usually it is more reliable to use time zone-aware WP functions, such as current_time(), rather than vanilla PHP functionality.