Need to add class to first element in a foreach loop

Use below code <?php $isFirst = true; $i=1; foreach ( $attachments as $attachment ): $description = $attachment->post_content; if($i==1) { echo ‘<div class=”item’.$isFirst.'” data-description=”‘ . $description . ‘”>’; echo wp_get_attachment_image($attachment->ID, ‘large’); echo ‘</div>’; } else { echo ‘<div class=”item” data-description=”‘ . $description . ‘”>’; echo wp_get_attachment_image($attachment->ID, ‘large’); echo ‘</div>’; } $i++; endforeach; ?>

How to add text to the start of all comments?

You can try the comment_text filter: /** * Prepend text to each comment content. */ add_filter( ‘comment_text’, function( $comment_text ) { $text=”Some text”; return $text . $comment_text; }); if you’re displaying the comment text with: <?php comment_text(); ?>

Execute a function every hour in the background

I setup something similar. Using IIS – look into writing a .bat file which fires off a php shell script to do whatever it is you need to accomplish. once you have that bat file working, setup a “scheduled task” in IIS http://technet.microsoft.com/en-us/library/cc721871.aspx if you are on a linux system, then use crontab https://www.freebsd.org/doc/handbook/configtuning-cron.html If … Read more

Syntax error in a shortcode function

You need to escape your quotes, or use doubles, or use heredoc: // Escaped return ‘<div id=”xxxx-xxxxxx”></div> <script type=”text/javascript”> window._taboola = window._taboola || []; _taboola.push({ mode: \’xxxxxxx-xxxxx\’, container: \’xxxxxx-xxxxxxx\’, placement: \’one word word\’, target_type: \’mix\’ }); </script>’; // Doubles return ‘<div id=”xxxx-xxxxxx”></div> <script type=”text/javascript”> window._taboola = window._taboola || []; _taboola.push({ mode: “xxxxxxx-xxxxx”, container: “xxxxxx-xxxxxxx”, placement: … Read more

Get title attribute from galleries

WordPress actually uses a Built-in Post Type for Attachments ( called attachment ) so you can use some of the same functions like get_the_title() which is what you’re looking for. Though, I did take some liberties by modifying your code below, using a foreach instead of a for loop: $gallery = get_post_gallery( 7, false ); … Read more

Add shortcode in my div

You need the do_shortcode() function <?php echo do_shortcode(“[contact-form-7 id=”54″ title=”Contact form 1″]”); ?> I have not tested your shortcode.

Assign category a default post type

I’m also wanting the post to be assigned the post type “Video”. You can’t just change a post to a different Post Type. There is a difference between “Post Type” and “Post Format”. From your examples I assume you would like to change the “Post Format”, as per the codex http://codex.wordpress.org/Function_Reference/set_post_format, you would need to … Read more