Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a wordpress plugin that displays videos through a shortcode. My problem is it assigns the div's with ID's such as video-1-player, video-2-player, etc. I need to create a function that searches my content for <div id="video-(any number here)-player"> and adds a class inside the div.

I found this code which searches for the first image and than you can print it. My PHP isn't good enough for me to edit it for how i need. Maybe this will help you?

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
share|improve this question
add comment

2 Answers

Try the Search and Replace plugin: http://wordpress.org/extend/plugins/search-and-replace/

This searches for strings and will allow you to search for every instance of video-x-player, using a regex for the number. If you don't want to use regex searching on video- will bring up every instance that is already in your database.

If you intend to keep using that video plugin you may wish to edit the plugin to give you the ID's you want or to automatically add class names.

share|improve this answer
    
I dont need a plugin. I need a simple small function... –  cnotethegr8 Jun 10 '11 at 11:58
    
If it's such a simple, small function, why bother asking for help with it? The best approach is to modify the Video Player Plugin's shortcode function definition, so that it outputs IDs in the format that you want. You're not going to get that with a "simple, small function." –  Chip Bennett Jun 10 '11 at 17:40
    
The reason I ask help with it, is because my knowledge on PHP is vary minimal. Anyone who really knew PHP would be able to give me a code. Especially with the reference code above. Its basically what I need except instead of 'finding' the first image and putting it in a variable, I need to find an ID and add a class... –  cnotethegr8 Jun 11 '11 at 18:23
add comment

Why do you need a class inside the <div>? Are you trying to apply CSS styles to it?

If so, why not just use CSS? For example:

div[id^="video-"] {} 

...will target any DIV whose ID value starts with "video-"

share|improve this answer
    
It is for CSS, and even tho i didn't think about using the 'starts with' for my style this still wouldn't work. The shortcode outputs 4 nested divs. All having id="video-" in the beginning, (but the ending is whats different). I dont want to style to all the divs. And another note is this needs to work with IE7. Im not sure if this method does... –  cnotethegr8 Jun 11 '11 at 18:27
    
Which div in the nest do you want to style? The first? The last? One in the middle? –  Chip Bennett Jun 11 '11 at 19:49
    
I would like to get the first div. From there, any of its children are straight forward to get at. I just dont want to write styles for the top div, and than have to write counter-styles for its children. –  cnotethegr8 Jun 11 '11 at 19:53
    
What's the problem with writing "counter" styles for child DIVs? –  Chip Bennett Jun 11 '11 at 20:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.