Category: PHP

Use a custom template for all subapges of a parent page in WordPress

Add this code to your functions.php file from your template and replace the $page_id variable with the ID from your parent page ID and replace page-template.php with the template file you want to use for your subpages. $page_id = 100; $page_children = get_pages('child_of=$page_id');foreach($page_children as $child){ $current_page_template = get_post_meta($child->ID,'_wp_page_template',true); if($current_page_template != 'page-template.php') update_post_meta($child->ID,'_wp_page_template','page-template.php'); }  

Filter posts with a certain custom field value in wordpress

Add the meta_key and meta_value parameters to your wp_query where the meta_key is the name of the custom field and the meta_value is it's value. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => 4, 'meta_key' => 'show_on_homepage', 'meta_value' => '1', ); $temp = $wp_query; $wp_query = new … Continue reading Filter posts with a certain custom field value in wordpress

Fetch all tweets with a certain hashtag and store them in the database

I wrote a small script that gets all tweets with a certain hashag and stores them in a database. When the tweets exists in the database, it won’t be added again. $hashtag = "php5"; $json = file_get_contents("http://search.twitter.com/search.json?rpp=100&q=%23" . $hashtag); $results = json_decode($json)->results; $conn = mysql_connect("localhost", "root", "root"); mysql_set_charset('utf8',$conn); $db = mysql_select_db("twitter"); foreach($results as $result){ $tweet_id … Continue reading Fetch all tweets with a certain hashtag and store them in the database

Removing the index.php from your codeigniter URL

Removing the index.php from your codeigniter URL

When you create a standard new codeigniter application, there’s always a index.php in your url. It’s kind of ugly in your url so I prefer to remove this. To remove this you need to do a couple of things: change the $config[‘index_page’] to $config[‘index_page’]=”“ instead of $config[‘index_page’]=“index.php” This will only work is mod_rewrite is enabled on your webserver! Next … Continue reading Removing the index.php from your codeigniter URL

Multi-language support with Smarty Gettext

With smarty you can make language files containing all the words that need to be translated and smarty will replace the language variables with the correct language. This is based on Gettext. Smarty is also able to automatically check the browser language. I found this language class on the http://smarty.incutio.com/ website.  usage: Make a file in your … Continue reading Multi-language support with Smarty Gettext