Welcome to Free-PHP.net

    Free-PHP.net strives to be the premier resource for php developers and programmers. Our goal is to provide the web development community with quality free php scripts, the latest scripting news, honest product reviews, and code snippets to use in your web design projects. We look forward to your feedback on how to improve the site and requests, so please feel free to contact us with your suggestions.


link directory our free scripts


Dec

08

Codeigniter for the Absolute Beginner

Posted by CodeMunkyX

If you are looking for an alternative PHP framework to ZEND or Symfony, then Codeigniter should peak your interest. Much like the other frameworks, Codeigniter utilizes MVC and actually includes a Model paradigm unlike ZEND. Be sure to check out the beginner’s tutorial listed below if you want to take the next step in exploring what Codeigniter has to offer. Enjoy!

Article Blurb

I have seen in some forums and different websites, some doubts about how codeigniter is organized and how can it help you as a coder be more efficient. The first thing people should know is, codeigniter is a PHP framework, made with the software architecture known as MVC which stands for Model-View-Controller. This architecture seperates the logic from user interface allowing independant development, testing and better maintenance. Codeigniter allows you to have your code much organized, making you look better at what you already do. This framework is made to facilitate the way you do certain things in PHP, and allow you to reuse your code, using PHP Object Oriented programming paradigm. Codeigniter, on my opinion, seems to be very user friendly, so it’s to which I would recommend the use of it, for any upcoming web developer.

Nov

13

WordPress Custom Field Image to Featured Image

Posted by CodeMunkyX

Do you have a theme that uses custom fields to hold image URLS and wish you could automatically set these as the featured post image, to be more compatable with other themes if you ever decided to change.

Well today is your lucky day, I ran across the need to do this on one of my recent free themes. Below is the code:


	// First lets get the custom field , we are assuming its called "thumb"
	$thumb = get_post_meta($post->ID, 'thumb', true);

	// Check if a post thumbnail is already set, if so don't do anything.
	if( has_post_thumbnail( $post->ID ) ) {

	} else {

		if ( ! empty($thumb) ) {

			// Download file to temp location
			$tmp = download_url( $thumb );

			// Set variables for storage
			// fix file filename for query strings
			preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb, $matches);
			$file_array['name'] = basename($matches[0]);
			$file_array['tmp_name'] = $tmp;

			// If error storing temporarily, unlink
			if ( is_wp_error( $tmp ) ) {
				@unlink($file_array['tmp_name']);
				$file_array['tmp_name'] = '';
			}

			// do the validation and storage stuff
			$id = media_handle_sideload( $file_array, $post->ID, NULL );
			// If error storing permanently, unlink
			if ( is_wp_error($id) ) {
				@unlink($file_array['tmp_name']);
				return $id;
			}

			// Set the featured image
			set_post_thumbnail( $post->ID, $id );

		}

	}

Nov

02

WordPress Display All Images Associated with Page

Posted by CodeMunkyX

This is a code snippet I use quite often to display custom galleries in my themes. Paste the following code within the loop of your page template.

echo '<ul id="Thumbnails">';

$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {

$image_attributes 	= wp_get_attachment_image_src( $attachment->ID ); // returns an array
$imgTitle	        = $attachment->post_title;
$imgCaption 		= $attachment->post_excerpt;
$imgDescription		= $attachment->post_content;

echo '<li><a href="' . $attachment->guid . '"><img '; 

if ( $attachment->post_name == $_GET['image'] ) { echo 'class="active"'; }

echo ' src="' . $attachment->guid . '" title="' . $imgCaption . '" alt="' . $imgTitle . ' - ' . $imgDescription . '"  /></a></li>' . "\n";

}
}

echo '</ul>' . "\n";
echo '<div style="clear: both;"></div>';

Nov

02

WordPress Style First Word of Widget Titles

Posted by CodeMunkyX

Similar to my last post about adding html to the first word of titles, this is the code to do the same with widget titles. Just copy the code below into your functions.php file.

// Adds <span></span> around the first word of Widget titles
function arixWP_widget_title($title) {
$title = preg_replace('/(^[A-z0-9_]+)\s/i', '<span>$1</span> ', $title);
return $title;
}
add_filter('widget_title', 'arixWP_widget_title');

Nov

02

WordPress: Add HTML tags to first word of title

Posted by CodeMunkyX

While working on a theme, I needed code to add span tags around the first word of my titles in order to style them differently. Below is the code to do it. Just copy it into your functions.php file.


		function arixWP_title()
		{

			global $post;

			$title = '<h2 class="title"><a href="' . get_permalink() . '" title="' . get_the_title() . '" rel="bookmark">' . get_the_title() . '</a></h2>';
			$title = preg_replace('/<a([^>]+)>([A-z0-9_]+)\s/i', '<a$1><span>$2</span> ', $title);

			echo $title;

		}	

Usage

Where ever you would like the title to show up paste the following code:


<?php arixWP_title(); ?>

Oct

06

Introducing Namespaces for PHP Developers

Posted by CodeMunkyX

If you write web applications in PHP for a living or or you have tackled a big project then you most likely would be interested PHP namespaces in version 5.3. This article does a great job at explaining what a namespace is and how to utilize them in PHP.

Article Blurb

PHP’s historical lack of namespace support has long been a sore spot for developers residing both within and without the PHP community. Lacking the ability to efficiently organize project libraries, PHP developers have long made do with various contrived hacks, including notably using an autoloader in conjunction with code organized within a nested folder structure. Such an approach is used by the PHP Extension and Application Repository (PEAR), as well as by popular frameworks such as the Zend Framework.

Oct

06

How to check when a MySQL table was last updated

Posted by CodeMunkyX

Great little article if you are interested in finding out when the last time a table in your mySQL database has been updated. This is ideal if you have forgotten to place an updated by or last updated column in your table.

Article Blurb

I recently had to update a MySQL schema and import new data into the table. But before I could do that I needed to check that no one had updated the table during the last 7 days and no new data had been stored. As the table itself did not have any update field of itself the only other option was to look into the MySQL ‘information_schema’ database.

Sep

19

WordPress Count Post Views Without Plugin

Posted by CodeMunkyX

Did you ever want to know how many times a particular post has been viewed? Well today is your lucky day. Just add the following snippets to your template files and watch the post views grow.

Usage

Add this to your functions.php

	// Display or Count how many times a post has been viewed.
	// id = the post id and action = display or count

		function arixWp_PostViews( $id, $action ) {

			$axCountMeta 	= 'ax_post_views'; // Your Custom field that stores the views
			$axCount 	= get_post_meta($id, $axCountMeta, true);

			if ( $axCount == '' ) {

				if ( $action == 'count' ) {
					$axCount = 0;
				}

				delete_post_meta( $id, $axCountMeta );
				add_post_meta( $id, $axCountMeta, 0 );

				if ( $action == 'display' ) {
					echo "0 Views";
				}		

			} else {

				if ( $action == 'count' ) {

					$axCount++;
					update_post_meta( $id, $axCountMeta, $axCount );

				} else {

					echo $axCount . ' Views';	

				}

			}	

		}

To count the views add this to your single.php template.

<?php echo arixWp_PostViews( get_the_ID(), 'count' ); ?>

To display the count outside the loop use this:

<?php echo arixWp_PostViews( get_the_ID(), 'display' ); ?>

If you want them to show in the loop use this instead.

<?php echo arixWp_PostViews( $post->ID, 'display' ); ?>

Sep

19

WordPress Widget – Custom Taxonomy

Posted by CodeMunkyX

Custom posts types are great right, but by default wordpress does not list them in your sidebars or menus.

This is a simple widget i created for one theme I was developing, basically it allows you to show your custom taxonomies in your sidebar widgets.

Download Now

Sep

13

WordPress – Custom Taxonomy Breadcrumbs

Posted by CodeMunkyX

While developing a theme that uses custom taxonomies and custom post types, I ran across the need to include breadcrumb navigation to the custom taxonomies. After a couple of days of searching around and not finding any real solutions, I ended up creating my own function to do it.

Enjoy

Copy this to your functions.php file

<?php

	function postTypeCrumbs($postType, $postTax) {

		$term 			= get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
		$taxonomy 		= get_taxonomy($term->taxonomy);
		$parents 		= get_ancestors( $term->term_id, $postTax );
		$parents 		= array_reverse($parents);
		$archive_link	= get_post_type_archive_link( $postType );

		echo '<ul class="ax_crumbs">';

		if ($taxonomy)  {
			echo '<li><a href="' . $archive_link . '" title="' . $taxonomy->labels->name . '">' . $taxonomy->labels->name . '</a> &raquo; </li>';
		}

		foreach ( $parents as $parent ) {
			$p 	= get_term( $parent, $postTax );
			echo '<li><a href="' . get_term_link($p->slug, $postTax) . '" title="' . $p->name . '">' . $p->name . '</a> <span>&raquo;</span> </li>';
		}

		if ($term) {
			echo '<li>' . $term->name . '</li>';
		}

		echo '</ul>';

	}
?>

Usage

Paste this whereever you would like the taxonomy to display.

<?php postTypeCrumbs('post type', 'taxonomy name'); ?>

featured wordpress themes