Show Custom Taxonomy Title

You can use single_term_title(): <h3><?php single_term_title(); ?></h3> To hide it if there are no posts, use the if ( have_posts() ) : function: <?php if ( have_posts() ) : ?> <h3><?php single_term_title(); ?></h3> <?php endif; ?> If not an archive, you can use get_term_by() to get the term object for the term and then echo … Read more

Apply CSS class to every second database record [closed]

Inside the loop you can use $the_query->current_post to get the index of the post currently being displayed. You can then check if the index is an odd or even number and conditionally add the class. Example: if ( 1 === $the_query->current_post % 2 ) { echo ‘class=”switchable”‘; }

How do I display the function the_content in this loop?

try this instead: … global $post; while ($q_query->have_posts()){ $q_query->the_post(); $loophtml .= “<li><span class=”list-question-title”>” . “<a class=”list-answer-link” href=”” . get_permalink() .””>” . get_the_title() . “</a></span>”; $loophtml .= get_the_content(); $loophtml .= “<span class=”list-number-answers”>” . get_comments_number() . ” comentarios</span>&nbsp;&#183;&nbsp<a href=”” . get_permalink() .””>Comentar</a>”; $loophtml .= “</li>”; } wp_reset_query(); …

How would I create a shortcode to display a custom post within a page or regular post?

There are great tutorials about shortcodes all over the web and some good examples here but just to get you started: add_shortcode(‘film_q’, ‘film_shortcode_query’); function film_shortcode_query($atts, $content){ extract(shortcode_atts(array( // a few default values ‘posts_per_page’ => ‘1’, ‘post_type’ => ‘film’, ‘caller_get_posts’ => 1) , $atts)); global $post; $posts = new WP_Query($atts); $output=””; if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); … Read more

Output 2 items within the Loop

Easy using WP query (get to know it…) <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=2’); // SET AMOUNT HERE ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><div class=”slide”><?php the_content(); ?></div></li> <?php endwhile; ?> </ul> Hope this helps. Let me know if you encounter any issuse. EDIT 1: * explenation – just added a small conditional … Read more

How do I exclude posts by custom field value?

You can use meta query in wp query to get required posts $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘city’, ‘value’ => ‘Melbourne’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘city’, ‘value’ => ‘Melbourne’, ‘compare’ => ‘NOT EXISTS’ ) ) ); $query = new WP_Query( $args );

Check to see if more than one post

Try this to get the count of posts: <?php $connected = new WP_Query( array( ‘connected_type’ => ‘posts_to_pages’, ‘connected_items’ => get_queried_object(), ‘nopaging’ => true, ) ); echo “<h2>Found: $connected->found_posts</h2>”; ?> You could write a variable like: $the_count = $connected->found_posts; Then test with an if if ( ( $connected->have_posts() ) && ( $the_count > 1 ) ) … Read more