Wednesday 15 September 2010

wordpress - CSS class for specific list item -


I want to add a CSS class to a specific NAV menu item (s) if the latest post of a certain custom post type is a

This is what I have found so far. It works fine but the CSS class is added to all menu items, how can I target specific li from the ID?

  function blog_menu_item_new_posts ($ squares, $ item) {global $ wpdb; $ Latest_post = $ wpdb- & gt; Get_var ("SELECT post_date FROM $ wpdb- & gt; Posts WHERE post_type = 'blogposts' and post_status =' Publish id id DESC limit 0,1"); $ Latest_post_date = strtotime ($ latest_post); $ Threshold = Strottom ("- 1 week"); If ($ latest_post_date> = $ threshold) {array_push ($ class, "new-post"); } Return $ class; } Add_filter ("nav_menu_css_class", "blog_menu_item_new_posts", 10, 2); This code is working to target only a specific menu item from the item (in this) (<)    

case ID 101): function blog_menu_item_new_posts ($ classes, $ items) {global $ wpdb; $ Latest_post = $ wpdb- & gt; Get_var ("SELECT post_date FROM $ wpdb- & gt; Posts WHERE post_type = 'blogposts' and post_status =' Publish id id DESC limit 0,1"); $ Latest_post_date = strtotime ($ latest_post); $ Threshold = Strottom ("- 1 week"); If ($ latest_post_date> = $ threshold) & amp; amp; ($ item-> ID == 101) {array_push ($ classes, "new-post"); } Return $ class; } Add_filter ("nav_menu_css_class", "blog_menu_item_new_posts", 10, 2);

No comments:

Post a Comment