How do I rewrite this loop as a new WP_Query style-loop?

You’re 95% of the way there already. Just add if ( $my_query->have_posts() ) and incorporate your $odd variable: <?php $my_query = new WP_Query(‘offset=5&showposts=10’); if ( $my_query->have_posts() ) : $odd = false; while ($my_query->have_posts()) : $my_query->the_post(); $odd = !$odd; ?> <div class=”<?php if ($odd) echo ‘uneven ‘; ?>post”> <h3><a href=”https://wordpress.stackexchange.com/questions/70713/<?php the_permalink(); ?>”><?php the_title(); ?></a></h3> <?php the_excerpt(); … Read more

How to get my loop to paginate?

In functions.php function my_theme_navigation() { global $shortname; if( get_option( $shortname . ‘_next_prev_or_paginate’ ) == ‘Next’ ) : // the block for next-prev navigation echo ‘<div style=”float:left”>’; next_posts_link(‘Older’); echo ‘</div>’; echo ‘<div style=”float:right”>’; previous_posts_link (‘Newer’); echo ‘</div>’; else : // the block for pagination global $wp_query; $big = 999999999; // need an unlikely integer echo paginate_links( … Read more

how to make nsfw post with thumbanil

get_post_meta is your friend: if ( has_post_thumbnail() ) { if ( ‘yes’ == get_post_meta( $post->ID, ‘NFSWEG’, true ) ) { echo ‘<img src=”https://wordpress.stackexchange.com/questions/82422/YOUR-IMAGE-HERE”>’; } else { the_post_thumbnail( array( 400, 400, true ), array( “class” => “aligncenter featured_image” ) ); } }

Display Posts Only with Specific Tag

In your template, the add_action you have there is way too late because by the time WordPress gets to your template, the query has already been performed. If this is for a category page, I’d do the following in your functions.php: //Display Gaming Trailers function display_gaming_trailers( $query ) { if ( $query->is_category() && $query->query_vars[‘category_name’] == … Read more

add to end of post in the loop with plugin

It sounds like you want a filter on the_content. function add_content_wpse_97277($content) { global $post; if ($post->ID == 123) { $content .= ‘additional content’; } return $content; } add_filter(‘the_content’,’add_content_wpse_97277′); I don’t know what conditions you need though. You did not explain that in the question. The above should match a post with an ID of “123”. … Read more

How to style first post differently with ‘get_template_part’?

If you are using post_class() in your content template like this … <div <?php post_class(); ?>> … you can filter that and add a special class: add_filter( ‘post_class’, ‘mark_first_post’ ); function mark_first_post( $classes ) { remove_filter( current_filter(), __FUNCTION__ ); $classes[] = ‘first-post’; return $classes; } Your first post in a loop will now have the … Read more

Get User_id outside wordpress,

AJAX requests (which you imply you are using but do not explain/demonstrate) do not load your active theme, which is where functions.php resides (unless you were referring to a functions.php file that you created in your plugin’s directory). As such, your call_user_func() is likely failing as the function that you are attempting to call is … Read more

PHP if post is already displayed, then

Track the IDs, and “exclude” them with post__not_in. It is hard to tell exactly what does what with the disjointed way you posted your code but the general case solution is .. $c_posts = new WP_Query(“showposts=10”); $tracker = array(); if ($c_posts->have_posts()) { while ($c_posts->have_posts()) { $c_posts->the_post(); $tracker[] = get_the_ID(); // more code } } $other_loop … Read more

Multiple Loops Breaking Pages

Your page is behaving weirdly because you are using query_posts which clobbers the main query. Anything else on the page that depends on the main query has the wrong information after your query_posts runs. Don’t use query_posts. $qry = new WP_Query(‘category_name=News and Events, Uncategorized&showposts=5’); if ($qry->have_posts()) { while ($qry->have_posts()) { $qry->the_post(); // your Loop as … Read more