Loop posts only excluding first post

You don’t need separate queries, you can run multiple loops on the same query- // output first post if( have_posts() ){ the_post(); the_title(); } // output the rest of the posts… if( have_posts() ){ while( have_posts() ){ the_post(); the_title(); } } You can also use rewind_posts() to reset the current post back to 0, as … Read more

Pagination gives extra page with no results

I am not sure, but I have a guess that it is because you are using pagination and offset at the same time. Pagination might be calculated for whole set, but you are reducing set size with offset so number of pages becomes overestimated.

Help with Changing loop.php?

<?php if( is_archive() && is_category() && !is_tag() && !is_search() ): ?> <!– BEGIN .archive-title –> <h1 class=”page-title”> <?php if ( is_day() ): ?> <?php printf( __( ‘Daily Archives: %s’ ), get_the_date() ); ?> <?php elseif ( is_month() ): ?> <?php printf( __( ‘Monthly Archives: %s’ ), get_the_date( ‘F Y’ ) ); ?> <?php elseif ( … Read more

Combining the_excerpt with the_content

The key is to use user-defined excerpts, rather than auto-generated excerpts. For example: <div <?php post_class(); ?>> <?php // If post has defined excerpt, output it here if ( has_excerpt() ) { ?> <div class=”first-paragraph-excerpt”> <?php the_excerpt(); ?> </div> <?php } // Now output the content the_content(); ?> </div> <!– .post –> You’ll need to … Read more

Problem the_permalink

the_permalink() will echo the content immediately. You can’t use it for string concatenation. What is happening is that your permalink gets echoed by the_permalink() before the string is finished building, so the permalink ends up in the wrong place. What you need instead is get_the_permalink(). Side note: Because PHP’s echo will take multiple parameters, separating … Read more

Why do I get `Call to a member function have_posts() on a non-object `? [closed]

Change if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); to if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); Why? When you call $the_query = new WP_Query($query); you’re storing the loop in a variable called $the_query. $query is an array of arguments that you’re passing to the new WP_Query() function. … Read more

Can I use both a custom excerpt and a trimmed excerpt?

We can try to filter the excerpt through the get_the_excerpt filter. By default, if we have a manual excerpt, the manual excerpt will be used and not the automatically created excerpt which is created by the wp_trim_excerpt() function. We can alter this behavior. What we will do is, when we are inside the main query … Read more

Make a custom loop inside single.php with pagination

As I far I know, get_posts() function can not be used to paginated results. It is intended to get an array of posts and it sets no_found_rows to true by default from WP 3.1. Pagination won’t work unless you set it to false, or better, use WP_Query. numberposts is also a invalid argument. $paged = … Read more

Does get_template_part pull data once in a loop?

get_template_part() calls locate_template(), and both functions are running file_exists() checks for the same file over and over. There is no caching. Meh. But … PHP has an internal cache for file look-ups, so a direct file access will not happen on every call. There is an edge case, most developers aren’t aware of: A file … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)