Solution Place the code bellow in functions.php file inside your theme’s folder. function randomPosts($numPosts = 5){ query_posts(array('orderby' => 'rand', 'showposts' => $numPosts)); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul> <li><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> </ul> <?php endwhile; endif; wp_reset_query(); } Change the layout to fit your needs. Calling randomPosts(); will show 5 random posts and if you want a different amount [...]
Continue reading...12. marts 2010
Kommentarer slået fra
The code Place the code bellow in your theme’s functions.php file. function commentCount($type = 'comments'){ if($type == 'comments'): $typeSql = 'comment_type = ""'; $oneText = 'One comment'; $moreText = '% comments'; $noneText = 'No Comments'; elseif($type == 'pings'): $typeSql = 'comment_type != ""'; $oneText = 'One pingback/trackback'; $moreText = '% pingbacks/trackbacks'; $noneText = 'No pinbacks/trackbacks'; elseif($type == 'trackbacks'): $typeSql = 'comment_type = "trackback"'; $oneText = 'One trackback'; $moreText = '% trackbacks'; $noneText [...]
Continue reading...9. marts 2010
Kommentarer slået fra
PHP Place the code bellow inside your theme’s function.php file. Don’t forget to change the “TwitterProfileName” with your twitter profile name. function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet [...]
Continue reading...4. marts 2010
Kommentarer slået fra
Part 1 – Overview of Functions, Database & Files Overview In this tutorial we’ll be creating a very simple blog system. We won’t be using OOP yet in this tutorial. For creating a Blog using OOP in PHP, another more advanced tutorial will be written and posted as well. The same goes for creating a more advance [...]
Continue reading...3. marts 2010
Kommentarer slået fra
In this tutorial we’ll be retrieving data from form fields. To do this we’ll first create an example form. We’re using the POST method to send the form data in the first example. Will later explain what this means, and how we can then retrieve the data from the form fields. Also the GET method [...]
Continue reading...3. marts 2010
Kommentarer slået fra
Assumptions You have an HTML form with a variety of inputs. The action attribute of the form points to a PHP file that contains the code below. Notes about code This code starts by creating an array that holds the name of various inputs being submitted via a POST. getFormData() is then called, where the required fields are [...]
Continue reading...3. marts 2010
Kommentarer slået fra
1) Function for stripping out malicious bits <?php function cleanInput($input) { $search = array( '@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments ); $output = preg_replace($search, '', $input); return $output; } ?> 2) Sanitization function Uses the function above, as well as adds slashes as [...]
Continue reading...25. februar 2010
Kommentarer slået fra
It has been a while since we’ve done a proper PHP & MySQL tutorial here, So today we are creating a simple, yet robust, file download tracker. Each file will have a corresponding row in the database, where the total number of downloads is saved. PHP will update the MySQL database and redirect the visitors to [...]
Continue reading...18. februar 2010
Kommentarer slået fra
Last week i wrote an article about disabling trackbacks and pingbacks in wordpress comments, but today instead of disabling them we will separate them from comments. To see how it looks you can check some of my articles here on wpCanyon. <?php if ($comments) : ?> <ol> <?php foreach ($comments as $comment) : ?> <li id="comment-<?php comment_ID() ?>" class='commentItem'> <!-- [...]
Continue reading...18. februar 2010
Kommentarer slået fra
It’s very important to secure your data in PHP correctly. Because if you don’t, your website is in risk of being harmed by SQL injections and other dangerous code injections, which you obviously don’t want. So to protect your website against these code attacks, this tutorial was written ;) This tutorial will explain the reasons to [...]
Continue reading...
12. marts 2010
Kommentarer slået fra