Apply class to every third list item? [duplicate]

add a simple counter and conditional check: $pages = get_pages(‘child_of=10’); $counter = 1; if ($pages) { echo ‘<ul class=”projectthumbs”>’; foreach ($pages as $page) { if ($counter == 3){ $class=” class=”YOUR_CLASS””; $counter = 1 }else{ $class=””; $counter = $counter +1; } echo ‘<li’.$class.’><a href=”‘.get_permalink($page->ID).'”>’; echo get_the_post_thumbnail($page->ID); echo ‘<span class=”projectthumbtitle”>’; echo get_the_title($page->ID); echo ‘</span>’; echo ‘</a></li>’; } … Read more

How to use array in function to get only value I want

There’s wp_list_pluck() to get certain fields out of arrays or objects: $object = new StdClass(); $object->foo = ‘Hi!’; $object->bar=”Yo!”; $array[‘foo’] = ‘Hi!’; $array[‘bar’] = ‘Yo!’; $result_obj = wp_list_pluck( $object, ‘foo’ ); var_dump( $result_obj ); // Result: string (3) Hi! $result_array = wp_list_pluck( $array, ‘bar’ ); var_dump( $result_array ); // Result: string (3) Yo!

Making my first wordpress template

Use this code to show the content of a post or a page: <?php the_content() ?> Use this code to show the title of a post or a page: <?php the_title() ?> This page can be useful if you are new to designing WP themes: http://codex.wordpress.org/Site_Design_and_Layout Here is a list of the template-tags you can … Read more

How to keep track of when a vote is cast?

The following lines of code both store the IP address and time of vote, // $ip holds $_SERVER[‘REMOTE_ADDR’] $voted_IP[$ip] = time(); // Save IP and increase votes count update_post_meta($post_id, “voted_IP”, $voted_IP); The time a vote is cast is already being stored for you in the post_meta table for the given post the person is voting … Read more

How do I define a lookup table that will work across all PHP elements of the template?

Loading it in the header should work, or on the init hook. You will need to declare it global as well. So… // define global $trans_home; $trans_home = array(‘en’ => ‘Home’,’it’ => ‘Home’,’de’ => ‘Home’,’zh’ => ‘首页’,’es’ => ‘Página de inicio’,’fr’ => ‘Page d\’accueil’); // and use in your templates global $trans_home; echo $trans_home[qtrans_getLanguage()];

First Byte Time (back-end processing)

That is a huge question and it is going to be hard to answer. And it is going to take a lot of research and trail and error on your part. As far as WordPress specific things go, analyze your code base. Poorly written plugins or themes can cause huge delays. A 3 second backend … Read more