+44 (0)785 715 1348
office@bogdans.co.uk

Currently Browsing: Web development

Get the href, title or target of all links within an HTML page 0

Posted on 31, January 2014

in Category Web development

In order to do that you need to use preg_match_all just like explained below: $url = ‘<a target=”_blank” href=”‘ . $query_logs_result[“url”] . ‘”>’ . $query_logs_result[“title”] . ‘</a>’; preg_match(‘~<a(.*?)href=”([^”]+)”(.*?)>~’, $url, $only_the_url); echo $only_the_url[2]; This will show the hrefs, any other param of $only_the_url will return differently

Read More

PHP – Convert objects to Arrays 0

Posted on 11, December 2013

in Category Web development

I’d suggest using sections from the sections below in order to convert with PHP from objects to Arrays $responseXml2 = (array) $responseXml; $responseXml3 = array_values($responseXml2); $responseXml4 = $responseXml3[4]; $responseXml5 = array_values($responseXml4); $responseXml6 = $responseXml5[0]; $responseXml7 = (array) $responseXml6; $responseXml8 = array_values($responseXml7); $responseXml9 = $responseXml8[3]; $responseXml5 = array_values($responseXml9); $responseXml6 = $responseXml5[0]; $responseXml7 = (array) $responseXml6; $responseXml8 = array_values($responseXml7); $responseXml9 = $responseXml

Read More

WordPress: get the featured image from the parent’s post 0

Posted on 11, September 2013

in Category Web development

Here’s what you need to do in order to get the image from the parent’s post //get the ancestors $familyTree = get_ancestors($post->ID,’page’); array_unshift( $familyTree, $post->ID ); //add the current page to the begining of the list //loop through the family tree until you find a result or exhaust the array $featuredImage = ”; foreach ( $familyTree as $family_postid ) { if ( has_post_thumbnail( $family_postid ) ) { $featuredImage = get_the_post_thumbnail( $family_postid, ‘full’ ); break; } } // if the page has a featured image then show it echo ( $featuredImage ? $featuredImage : “” )

Read More

WordPress – get post IT by title 0

Posted on 11, September 2013

in Category Web development

It returns the post id based on the post title. It may not work if multiple posts have the same title.. function get_post_by_title($page_title, $output = OBJECT) { global $wpdb; $post = $wpdb->get_var( $wpdb->prepare( “SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type=’post’”, $page_title )); if ( $post ) return get_post($post, $output); return null; }

Read More

WordPress: get the text between a href anchor tags 0

Posted on 11, September 2013

in Category Web development

This is what you have to do in order to get the content between the a href / anchor tags: $out_vector = getTextBetweenTags(‘a’, $out); function getTextBetweenTags($tag, $html, $strict=0){ /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ if($strict==1) { $dom->loadXML($html); } else { $dom->loadHTML($html); } /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the tag by its tag name ***/ $content = $dom->getElementsByTagname($tag); /*** the array to return ***/ $out = array(); foreach ($content as $item) { /*** add node value to the out array ***/ $out[] = $item->nodeValue; } [&hellip

Read More

PHP function to show the elapsed time in a nice way 0

Posted on 9, September 2013

in Category Web development

This function shows the elapsed time in a nice way (days left / remaining) – depending on the usage function themeblvd_time_ago() { global $post; $date = get_post_time(‘G’, true, $post); $chunks = array( array( 60 * 60 * 24 * 365 , __( ‘year’, ‘themeblvd’ ), __( ‘years’, ‘themeblvd’ ) ), array( 60 * 60 * 24 * 30 , __( ‘month’, ‘themeblvd’ ), __( ‘months’, ‘themeblvd’ ) ), array( 60 * 60 * 24 * 7, __( ‘week’, ‘themeblvd’ ), __( ‘weeks’, ‘themeblvd’ ) ), array( 60 * 60 * 24 , __( ‘day’, ‘themeblvd’ ), __( ‘days’, ‘themeblvd’ ) [&hellip

Read More

WordPress function to limit the number of characters 0

Posted on 9, September 2013

in Category Web development

This function limits a string down to a number of characters. The last parameter checks if the last word gets split or not. function limit_number_characters_string($string, $number, $words){ if ($words == true){ if (strlen($string) > $number){ $string = substr($string, 0, $number); for ($counter = strlen($string); $counter > 0; $counter–){ if (substr($string, $counter – 1, 1) == ” “){ return trim($string) . “..”; } else { $string = substr($string, 0, -1); } } } return $string; } else { if (strlen($string) > $number){ return substr($string, 0, $number) . “..”; } else { return $string; } } }

Read More

Upload WordPress post thumb image with PHP 0

Posted on 26, July 2013

in Category Web development

Here’s what you need to use in order to upload the thumb automatically with PHP instead of manually from the backend. $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $filename = basename($image_url); if(wp_mkdir_p($upload_dir[‘path’])) $file = $upload_dir[‘path’] . ‘/’ . $filename; else $file = $upload_dir[‘basedir’] . ‘/’ . $filename; file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => sanitize_file_name($filename), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); require_once(ABSPATH . ‘wp-admin/includes/image.php’); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail( $post_id, $attach_id )

Read More

YII blog database schema example 0

Posted on 28, March 2013

in Category Web development

YII blog example comes with a default database schema. Here’s the code to build it. CREATE TABLE tbl_lookup ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(128) NOT NULL, code INTEGER NOT NULL, type VARCHAR(128) NOT NULL, position INTEGER NOT NULL ); CREATE TABLE tbl_user ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, username VARCHAR(128) NOT NULL, password VARCHAR(128) NOT NULL, salt VARCHAR(128) NOT NULL, email VARCHAR(128) NOT NULL, profile TEXT ); CREATE TABLE tbl_post ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, title VARCHAR(128) NOT NULL, content TEXT NOT NULL, tags TEXT, status INTEGER NOT NULL, create_time INTEGER, [&hellip

Read More

CSS Mastery – CSS, HTML code examples 0

Posted on 7, March 2013

in Category Web development

ul.circle {list-style-type:circle} ul.square {list-style-type:square} ol.upper-roman {list-style-type:upper-roman} ol.lower-alpha {list-style-type:lower-alpha} Property Values circle The marker is a circle disc The marker is a filled circle. This is default square The marker is a square armenian The marker is traditional Armenian numbering decimal The marker is a number decimal-leading-zero The marker is a number padded by initial zeros (01, 02, 03, etc.) georgian The marker is traditional Georgian numbering (an, ban, gan, etc.) lower-alpha The marker is lower-alpha (a, b, c, d, e, etc.) lower-greek The marker is lower-greek (alpha, beta, gamma, etc.) lower-latin The marker is lower-latin (a, b, c, d, e, [&hellip

Read More

WordPress get page number 0

Posted on 7, March 2013

in Category Web development

< ?php the_ID(); ?> // Works inside of the Loop function function_name() { global $post; $thePostID = $post->ID; } // Works in single post outside of the Loop function function_name() { global $wp_query; $thePostID = $wp_query->post->ID; } //Get the latest post ID number $post->ID ORDER BY post_date ASC LIMIT 1 //Get the earliest post ID number $post->ID ORDER BY post_date DESC LIMIT

Read More

Change Joomla Admin Password 0

Posted on 7, March 2013

in Category Web development

Q. How do I recover my admin password? A. You cannot recover the existing password, but you can reset it to a new password. The passwords are stored using a one-way MD5 hash which prevents recovering the password. But you can reset the password by editing the password field in the database. Set the password to a known value and then you may log-in using that new password. The password is stored in the MySQL database jos_users table password field. (change this for your table prefix if different) Use a MySQL utility such as phpMyAdmin or MySQL Query Browser to edit this field. Open [&hellip

Read More