How To Schedule Events In Your WordPress Website
The following snippet will let you schedule events in your WordPress website.
1 2 3 4 5 6 7 |
if (!wp_next_scheduled('my_task_hook')) { wp_schedule_event( time(), 'hourly', 'my_task_hook' ); } add_action( 'my_task_hook', 'my_task_function' ); function my_task_function() { wp_mail('you@yoursite.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.'); } |
How To Show Posts For Category
You do turn selective one-to-many times in choosing the posts for category. While the thing can be achieved by manually but to ease the job, using the snippet below you can show posts for category as per the way you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/** * Show latest posts for category * * @return * @param object $cats * @param object $show[optional] */ function show_title_cat( $cats, $show=5 ) { global $post; $posts = query_posts('cat=' . $cats . '&showposts=' . $show ); echo "<ul>"; foreach ($posts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endforeach; echo "</ul>"; } |
Snippet Source/Credit: undolog.com
How To Automatically Create Greybox Imageset From Images Attached To Post
Using the following snippet you will be able to automatically create greybox imageset from images attached to post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<!--Automatic Greybox--> <?php //Die zum Post gehoerenden Bilder ins Array $images schreiben //Put images from post in to array $images. Order by menu order defined in post gallery $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); //Pruefen, ob dem Beitrag Bilder angehaengt wurden. //check if there are any images attached to the post if (isset($images)) { //Den Zaehler auf 0 setzen //set counter to 0 $count=0; //Alle Bilder im Array $images nacheinander durchlaufen //go through all images in array $images foreach( $images as $image ) { $imageID = $image->ID; //fuer jedes Bild im Array die URL von sowohl der Mittleren, als auch der grossen Groesse ermitteln. //get medium and large image url for image $medImageSrc = wp_get_attachment_image_src($imageID, $size='medium', $icon = false); $largeImageSrc = wp_get_attachment_image_src($imageID, $size='large', $icon = false); //Wenn es sich um das erste Bild im Array handelt... //If it's the first image in the array if ($count==0) { //Den Greybox-Code mit einem Vorschaubild ausgeben //output Greybox Code with medium size preview echo"<a href='$largeImageSrc[0]' rel='shadowbox[Bilder]'><img src='$medImageSrc[0]' border='0'></a>"; } //alle Bilder ,die nach dem erstern Bild kommen //this is for all the images that come after the first one else { //unsichtbare Greybox-Verknuepfung darstellen. //create invisible Greybox-Links without preview image echo"<a href='$largeImageSrc[0]' rel='shadowbox[Bilder]'></a>"; } //Zaehler erhoehen. //increase counter $count++; } //foreach } ?> <!--ENDE Automatic Greybox --> |
Snippet Source/Credit: Snipplr
How To Call jQuery In WordPress
The following snippet will you call jQuery in WordPress.
1 |
<?php wp_enqueue_script("jquery"); ?> |
How To Create Short URL For Posts In WordPress
The following snippet will let you create short URL for posts in WordPress.
1 2 3 4 |
//place in functions.php in theme folder <?php function getTinyUrl($url) { $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url); return $tinyurl; } ?> //call the function on the page <a href="http://twitter.com/home?status=Currently reading <?php the_title(); ?> : <?php $turl = getTinyUrl(get_permalink($post->ID)); echo $turl ?>" title="Tweet this">Twitter link</a> |
Snippet Source/Credit: Snipplr
How To Allow Multisite Network In WordPress
The following snippet will let you allow multisite network in WordPress.
1 2 |
/** Sets up WordPress Network for multisite. */ define('WP_ALLOW_MULTISITE', true); |