Show that current post is number X out of X
I would do this with $query->current_post and $query->post_count with $query = new WP_Query(args);. With this you may get the position and the total of posts.
I would do this with $query->current_post and $query->post_count with $query = new WP_Query(args);. With this you may get the position and the total of posts.
As the Codex says, this is the code block to query for only the Top Label categories — the parents. With this, I used the PHP function count(). <?php $args = array( ‘parent’ => 0, ‘hide_empty’ => 0 ); $categories = get_categories( $args ); echo count( $categories ); ?>
So basically what you need to do is paste the following code in your theme’s sidebar.php file or any other file where you want to display custom WordPress archives. <?php global $wpdb; $limit = 0; $year_prev = null; $months = $wpdb->get_results(“SELECT DISTINCT MONTH( post_date ) AS month,YEAR( post_date ) AS year, COUNT( id ) as … Read more
when you use get_users() it retrieves an array of users matching the criteria given in $args which means you can simply use PHP’s count() function e.g: $users = get_users($args); $number_of_users = count($users);
I was curious and decided to check it out, regardless if it’s relevant for a CSS problem 😉 I first peeked into the database tables to find more about the menu structure: Menu – building blocks Each navigational menu is registered as a term in the nav_menu taxonomy. Then when we add items to that … Read more
I’m posting a new answer because I found this thread while searching for the same thing and the solutions here weren’t optimal. The post_type argument can be a string or an array of post types. function custom_count_posts_by_author($user_id, $post_type = array(‘post’, ‘page’, ‘custom_post_type’)) { $args = array( ‘post_type’ => $post_type, ‘author’ => $user_id, ‘post_status’ => ‘publish’, … Read more
A gallery is a post with attached media. So maybe you’ll find hints like this : just hook on get_comment_numbers() and pass $attachment_id. I think in this case you’ll have to add an SQL query to get the comment count for attachment and then you’ll be able to add it to the total number of … Read more
You could initialize a second counter variable that increments when your first counter variable increments, and use that with modulus to alternate your code blocks. First initialize two counter variables: <?php if (have_posts()) : $show_alternate = 1; $which_alternate = 1; while (have_posts()) : the_post(); ?> Then in your .pin-alternate-content output code you could do something … Read more
First, go to Settings->Reading->Blog pages show at most->25. Or change the posts_per_page in main query to 25. Then, try this code in your template: if (have_posts()) : $count = 0; $paged = ( get_query_var(‘paged’) > 1 ) ? get_query_var(‘paged’) : 1; while (have_posts()) : the_post(); $count++; if ($count <= 3 && $paged === 1) : … Read more
The Easy Way This is by far and away the easiest approach to this, but unless you are willing to be a little bit flexible with how you present your archive it’s not for you. The easy solution is achieved using the wp_get_archives() function. Unfortunately though there is no filter available to manipulate the output, … Read more