List posts based on first letter of posts

This is the code I get from here, but I don’t remember the exact page, and this is my working page of letter B on my website (using the same code as you see below) <?php /* Template Name: Locali per lettera A WordPress template to list page titles by first letter. You should modify … Read more

Using pagination with get_posts on page type

You should check your code because you have some sentences that will make your pagination function returns empty value. For example, the next piece of code will get you out because you are in a page template, so is_singular() returns true: if( is_singular() ) return; Also, you are using the global $wp_query object inside your … Read more

Varying the number of posts per page from the first one

Thanks to s_ha_dum for the tip. I managed to solve it by setting the offset parameter in the special case of 2nd page onwards for the front page as follows: function limit_posts_per_home_page() { $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $first_page_limit = 5; $limit = get_option(‘posts_per_page’); if (is_front_page()) { if ($paged == 1) { $limit … Read more

Change class=”page-numbers” in pagination

The paginate_links() function, located in wp-includes/general-template.php, doesn’t allow for certain parts of the HTML (such as the page-numbers class) to be customized. A simple string replacement will not work due to the way that the classes are generated, as highlighted in this excerpt of code from paginate_links(): $page_links[] = ‘<a class=”prev page-numbers” href=”‘ . esc_url( … Read more

How can I see all of a post’s comments on a single page as a reader, if pagination is enabled?

Just build a link that has some query args: printf( ‘<a href=”http://example.com/all-comments?pid=%s”>All comments</a>’ ,get_the_ID() ); Then add a page with a a permalink of all-comments, so you have something to target. There you attach a template like the following (just a base to work off): <?php /** * Template Name: All Comments */ // Abort … Read more

Single Page View for Paginated Posts

Yes, it is possible, and I use it on my own site. Here it is in action: my Settings API post is paginated, but can viewed on a single page, using the “Single-Page View” link. First, you need to prepare a custom query variable, e.g. in functions.php, add the following: function cbnet_parameter_queryvars( $qvars ) { … Read more

Next/Previous Links in same category

previous_post_link takes 5 params, but you use only 2 of them. Let’s take a look at other 3: in_same_term (boolean) (optional) Indicates whether previous post must be within the same taxonomy term as the current post. If set to ‘true’, only posts from the current taxonomy term will be displayed. If the post is in … Read more

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