Display the loop using wordpress shortcode
September 23, 2009
The loop is the easiest way to display WordPress posts, perfect for those sites who are using WordPress as a CMS. But we can create a shortcode that will make post displaying simpler. Use this shortcode below to create a loop on a page, post or sidebar. Just use template tags and html like you would in a normal loop to create your layout. The sample below displays an unordered list with titles and links to the post. Just paste code in your functions.php file. Or if you want, you can use it in a plugin. // The Loop /* *... [Read the full story]
get wordpress custom fields outside the loop
June 12, 2009
Custom fields are very useful and are used on many WordPress blogs. But how to easily get custom fields values outside the loop? To display a custom field value outside the loop, simply use the following code. Don’t forget to replace Myfield on line 4 by the name of the custom field you want to display. <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'MyField', true); ?> Read More →
Use two or more loops without duplicate wordpress posts
December 23, 2008
How to use multiples loops without having the duplicate wordpress posts? There’s probably many other ways to achieve the same effect. But here’s a pretty nice way to avoid duplicate posts in two or more loops. To avoid wordpress post duplication, we started by creating a php array. And adding the IDs of the posts we get in the first loop to that array: <h2>Loop NO1</h2> <?php $ids = array(); while (have_posts()) : the_post(); the_title(); ?> <br /> <?php $ids[]= $post->ID; endwhile; ?> Now,... [Read the full story]
Get wordpress permalink outside of the loop
December 15, 2008
If you want to get a permalink outside of the loop. Here’s how to do it easily. To get a permalink outside of the loop, you have to use the get_permalink() function. That function takes a single argument, which is the ID of the post you’d like to get the permalink: <a href="<?php echo get_permalink(10); ?>" >Read the article</a> You can also use this function with the $post global variable: <a href="<?php echo get_permalink($post->ID); ?>" >Read the article</a> Read More →
Access wordpress post data outside the loop
December 6, 2008
How he can access post data outside the loop? paste the following function on the functions.php file from your theme. This function takes a singles argument, which is the ID of the post you’d like to access data. It will return an array, containing post title, date, content, author id, post id, etc. function get_post_data($postId) { global $wpdb; return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$postId"); } To use the function, use the following anywhere on your theme files: <?php $data =... [Read the full story]



















