This should do it:
$real_current_post = $wp_query->current_post + 1;
switch( $real_current_post ){
case 2:
// Do something for 2
break;
case 5:
// Do something for 5
break;
case 7:
// Do something for 7
break;
}
You may need to globalize $wp_query, but as long as you’re using the normal template hierarchy, it should already be in scope. If you do use global $wp_query;
, use it before the loop starts.
Related Posts:
- remove_action or remove_filter with external classes?
- Why, Where, and When to use reference pointers in filters/hooks?
- Combining action and filter?
- Suppress the_content filter in a nested loop
- Difference Between Filter and Action Hooks?
- Trouble understanding apply_filters()
- Remove parent theme action in child
- How to do_action and get a return value?
- Remove an action from an external Class
- Is it possible to use object in add_action?
- How to correctly get post type in a the_title filter
- How to publish a post with empty title and empty content?
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- Add a Custom Field in Comment Box AFTER text area BUT BEFORE Send button
- Actions or filters fired when data is saved in a custom table
- Using wp_insert_post and post_update_meta but need to fire save_post afterward
- What’s the difference between hooks, filters and actions? [duplicate]
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Please explain me what the do_action does
- Having an add_action( ‘user_new_form’,) [closed]
- Using auth_redirect returns cannot modify header information
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- Problem:Save Several Duplicate posts in The Database and then Error nesting level of ‘100’ reached
- Display different number of posts from one category on the different pages
- How to remove an action added by a child theme of Genesis
- how can I use add_action with external class which the function contain 2 argument?
- remove_action not working with procedural function
- Why Should We Use wp_clear_scheduled_hook and What it Does?
- Woocommerce Change placement with wrapper
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- How to get current action?
- Which action fire in front-end single post only
- how to change appearence of the content of default post list columns?
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Sort Posts By Category?
- Custom search form to display users only
- Removing an action, or dequeueing style – Both not working
- How do I add a TinyMCE row that all users can see, instead of just admins?
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- How to remove function?
- Validate form in functions.php, send errors back to template
- How to return only one instance of each, from the entire loop
- Is it acceptable to treat a filter like an action?
- Shortcodes — Using add_action, add_filter in the shortcode
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Is there way to run a code every time when any cron is run?
- Building a request processor for multi-page forms, etc using $_GET requests
- How to customize the “Insert/edit link” popup box?
- need help looping add_action in wp
- How can I output all apply_filters and do_action?
- How to allow code block in wordpress comments
- How to get all queries’s results after they have executed?
- Create new custom post and post category of same name
- remove_action: how to access to a method in an child class?
- Why is my css and js not enqueued until footer?
- Hook add_attachment error
- login_headertitle is deprecated since version 5.2.0
- W3TC manual cache flush does not work
- add_action.. will work if function is empty?
- call custom action after delete account
- How include css class based on post ( in loop ) slug?
- How to find list of all functions bind to a particular hook from my plugin?
- Register new user, assign custom role then send email
- Dynamically adding filters
- Trying to write a function in an external php file to manage admin menu visibility
- remove_action: Initial attempt failed while a later attempt worked
- Exists filter or action that change Add New Post link?
- Action inside another action not working
- What is the action or filter for adding information under the Permalink in Edit Post/Page?
- How would I use a filter to remove header banner on certain post types
- register_post_type not working in wordpress 3.6
- How to use add_action inside files included by theme’s functions.php
- output custom Posts on a Page
- Fix warning: Missing argument
- Replace Data In Post & Update Meta Field Post Is Saved
- WordPress sent multiple requests on update
- do_action in API call
- Post Click Redirect to Custom URL instead of Single Post Page
- Overriding Plugin function in your child theme
- add_action with associative array
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Does anybody know what the $current_screen ->id for customizer.php is?
- Remove action added in plugin class from theme
- Remove action from plugin
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- What problems could happen if I replaced add_filter and add_action with the function calling
- Adding a conditional to work on certain pages/page templates to an add_action()
- Adapting functions from Genesis theme
- Remove posts_orderby filter then add it back in
- Filter wp_dropdown_categories Per Post Type
- Settings in functions.php used by a plugin
- Adding to an array & passing it through do_action/apply_filters
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Invoke a function before the action hook
- Passing arguments in add_action inside search template
- remove an action hook function on a plugin from a theme
- Is it possible to make get variable out of filter in Class?
- GET form action. Redirect to self
- A way to see real changes of posts inside an action?