How does the ternary operator work in the wordpress loop post?

The double colon in this case is part of the alternative syntax for control structures. That’s not the ternary operator. You could also write instead: if ( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } I prefer the second style, most code editors enable automatic folding with it, so I can close … Read more

Only show posts from a certain category?

You need to modify your WP_Query loop. Add a tax_query argument to filter the category you want. $portfolioloop = new WP_Query(array( ‘paged’ => get_query_var(‘paged’), ‘post_type’ => ‘news’, ‘posts_per_page’ => 4, ‘tax_query’ => array( // Note: tax_query expects an array of arrays! array( ‘taxonomy’ => ‘portfolio’, // my guess ‘field’ => ‘id’, ‘terms’ => 51, ), … Read more

Targeting a Certain Post in Loop (CSS)

They key is here: <li <?php post_class(); ?> id=”post-<?php the_ID(); ?>”> You can add a parameter to the post_class call, e.g.: $counter = 0; $custom_query = new WP_Query(‘cat=2687&posts_per_page=3’); //Top of the page – Top Photo Category while($custom_query->have_posts()) : $custom_query->the_post(); $counter++; $column = $counter %3; // 3 columns, use module to get the remainder $class = … Read more

Displaying the last page of posts

Is it possible to load in the last page of posts first? Order DESC instead of ASC and make use of the posts_clauses filter. function wpse_59557_order_desc( $pieces ) { // Add conditionals here and abort in cases, where we don’t want this, for e.g.: // if ( ! is_home() OR ! is_front_page() ) return; // … Read more

the_excerpt not showing posts

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/60224/<?php the_permalink(); ?>”><?php the_title(); ?></a> <?php the_excerpt() ?> <?php endwhile; else: ?> <p>Nothing to see here.</p> <?php endif; ?> This is the right syntax to show title and the excerpt on home page.

Loop to display random posts only if a custom field matches category

Something like this should be the query you want to run, it adds a condition to the page query that requires the value in “meta_field” to equal the current category’s title. global $wp_query; $args = array(‘meta_query’ => array( array( ‘key’ => ‘meta_field’, ‘value’ => single_cat_title(“”, false), ‘compare’ => ‘=’ ) ) ); query_posts(array_merge($wp_query->query, $args)); // … Read more

Most recent post from another database

The WordPress wpdb class is a little different than the normal way of querying in that you run “vanilla” database queries. You can see documentation on the wpdb class on the WordPress docs: http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database Also, in regard to your code, you should be able to change the line here: $originaldb->query_posts( ‘posts_per_page=1’ ); To something like … Read more

Loop after page content

Updating a theme isn’t that hard. But it’s necessary to let it play nice with the current version of the core. Here’re some notes on what you might need to do: Query Templates Post Thumbnails & featured images The query Nowadays, we’re using get_posts() or new WP_Query for such cases, where you need to do … Read more