Techcoholic

Author: vytautas

20 Best PHP Frameworks For 2014

1
  • by vytautas
  • in PHP
  • — 11 Aug, 2014

PHP is very powerful and one of the most popular coding language among web programmers. Majority of the most popular websites on the web are based on PHP programming language. In this article, we are looking to help you choose the best PHP framework for 2014.

Every developer knows that a proper framework enables to create applications quicker, safer and more efficiently. Choosing a right framework before building your application is crucial for robustness and success. PHP frameworks are super useful tools for web development, as they are real time-savers when it comes to creation and maintenance of the PHP website.

Generally framework consists of:

  • A Toolbox – a set of prefabricated, rapidly integratable software components.
    It means writing less code, with less risk of error. It also means greater productivity and the ability to devote more time to doing those things which provide greater added value, such as managing guiding principles, side effects, etc.
  • A Methodology – an “assembly diagram” for applications. A structured approach may seem constraining at first. But in reality it allows developers to work both efficiently and effectively on the most complex aspects of a task, and the use of Best Practices guarantees the stability, maintainability and upgradeability of the applications you develop.

There are a lot of solid PHP frameworks on the market, so it is probably hard to choose one. We have gathered a list of the best PHP frameworks currently on the market and share our insights in finding the best one for your application. Every framework has its own advantages as well as disadvantages, so if you have a preferred Framework by which you work with aside from the ones listed here, please do let us know by dropping us your feedback in the comment section below.

1. Laravel : The PHP Framework for Web Artisans

Laravel - PHP Framework for Web Artisans

Laravel is a free, open source PHP Web application framework, designed for developing MVC web applications. In our opinion, Laravel is the best overall PHP framework of 2014. I personally believe that Laravel has taken PHP frameworks to the whole new level. Laravel helps you create wonderful applications using simple, expressive syntax, aiming to take the pain out of web development by easing common tasks, such as authentication, routing, sessions and caching. Laravel is well readable and well-documented that helps you speed up your coding. Laravel makes development easy and more creative for developers and lets them produce some outstanding result with it. With Composer you can manage all your application’s third-party packages, and works great on MySQL, Postgres, SQL Server, and SQLite.

Laravel uses the solid, tested components of the Symfony framework along with other popular packages to provide a modern framework that provides easy conventions, utilizes modern programming patterns and makes development a breeze.

Laravel has changed my life. The best framework to quickly turn an idea into product.

Maksim Surguy

Laravel reignited my passion for code, reinforced my understanding of MVC, and made development fun again!

Jozef Maxted

Laravel kept me from leaving PHP.

Michael Hasselbring

2. Phalcon

Phalcon - the fastest PHP Framework

Phalcon is the fastest framework on the list. Built on C, but offered as PHP extension, it offers no compromise speed wise. It offers high performance and lower resource usage. There’s no need to learn or use the C Language, as the functionality is exposed as PHP classes ready to use. By creating a rich, fully featured framework written entirely in C and packaged as a PHP extension, Phalcon is able to save processor time and boost overall performance.

In the past, performance was not considered one of the top priorities when developing web applications. Reasonable hardware was able to compensate for that. However when Google  to take site speed into account in the search rankings, performance became one of the top priorities alongside functionality. This is yet another way in which improving web performance will have a positive impact on a website.

3. Symfony 2

Symfony2 PHP Framework

Symfony is a PHP framework for web projects. It speed up the creation and maintenance of your PHP web applications. Replace the repetitive coding tasks by power, control and pleasure.

Symfony is a set of reusable PHP components and a PHP framework for web projects. It is well documented, it is free under MIT license, and it is getting more and more popular every day. Drupal, one of the most popular CMS systems, as well as phpBB, one of the most used discussion board system, use symfony.

The is powerful, scalable and flexible. Yet it is considered by many, especially those new to frameworks, to have a very steep learning curve.

This is true to a certain extent. At first glance, Models, Views, Controllers, Entities, Repositories, Routing, Templating, etc, altogether can appear very terrifying and confusing.

However, if you have grasped the fundamentals of PHP and HTML, have a basic understanding of modern web site development (in particular, Pretty URIs, MVC), and know how to CRUD a database/table, you are not far from developing a fairly good website, be it for your personal usage or business application.

4. Yii Framework

Yii PHP Framework

Yii is the fast, secure and professional PHP Framework. It is a high-performance PHP framework best for developing Web 2.0 applications. Yii Comes with rich features: MVC, DAO/ActiveRecord, I18N, caching, authentication and role-based access control, scaffolding, testing, open source, high performing, object oriented, database access object, easy form validation, default support for web services and many more. Yii Framework is ideal and perfect for developing social networking websites reduces development time significantly.

Yii Framework is a good choice for developing new high quality web-applications in rapid time. The well designed foundation with excellent documentation helped us developing Chives remarkable user experience and functionality in very short time.

David Roth

Yii Framework met all our needs! It worked equally good for both rapid prototyping and large scale web applications. It allowed us to focus on our unique idea while still offering the flexibility to bend our application in all directions we want.

Knut Urdalen

Yii is a simple but very powerful application framework with a very short learning curve. Its component-based design allows us to customize it for our needs without directly modifying it — maintaining upgradability. It’s amazing how we were able to use it not just on our main app and our API, but also on our daemons!

Blue Jayson

 

5. CodeIgniter

CodeIgniter PHP framework 2014

CodeIgniter is a proven, agile and open PHP web application framework with a small footprint. It is powering the next generation of web applications.

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.

CodeIgniter is right for you if:

  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need clear, thorough documentation.
  • You are not interested in large-scale monolithic libraries.
  • You need broad compatibility with standard hosting.
  • You prefer nearly zero configuration.
  • You don’t want to adhere to restrictive coding rules.
  • You don’t want to learn another template language.
  • You prefer simple solutions to complexity.
  • You want to spend more time away from the computer.

6. Cake PHP

CakePHP framework for web applications

CakePHP is one of the frameworks to follow in 2014. They are about to release a stable version 3.0 to the public. CakePHP makes building web applications easier, faster, and requires less code. It enabled to use code generation and scaffolding features to rapidly build prototypes. No additional XML or YAML file configuration is required, just setup your database and you are ready to bake. CakePHP is licensed under the MIT license which makes it perfect for use in common applications. The things you need are built-in: translations, database access, caching, validation, authentication, and much more are all built into one of the original PHP MVC frameworks. CakePHP comes with built-in tools for input validation, CSRF protection, Form tampering protection, SQL injection prevention and XSS prevention, helping you keep your application safe and secure.

7. Aura

Aura PHP framework

The Aura PHP Project is built for those who love clean code, fully decoupled libraries, and truly independent packages. This framework has quite a lot of users, is quite similarly used to CakePHP. Download a single package and start using it in your project today, with no added dependencies. The primary goal of Aura is to provide high-quality, well-tested, standards-compliant, decoupled libraries that can be used in any codebase. This means you can use as much or as little of the project as you like.

8. Zend Framework

Zend PHP framework

I’ve used Zend 1 and 2 in large scale enterprise projects for years. It has been one of the leading PHP frameworks with flexible architecture suitable for modern web applications for years. Recently I have switched over to a couple of newborn frameworks, but that is my personal preference.

Zend framework is designed with simplicity in mind. It is lightweight, easily customizable, and focused on most common needed functionality. It is built to dramatically ease the learning curve you must climb when adopting to a new framework. It is widely used, so quite well tested and safe.

Despite all the advantages, it is has quite different user experiences over the years. Some users call it “extremely complicated, the worst I have known so far”.

Extremely complicated framework, the worst that I have known so far (I have worked with symfony, Yii and django; all them are easier to learn)

 

Great framework with a great community and a lot of tutorials…nearly everything is good, just the speed could be better.

 

ZF is overly complicated. At some point you will find yourself struggling with it just to make things done. Syntax is too lengthy.
I’d say ZF is a great PHP class library but an awful web framework.

 

9. Kohana

Kohana PHP web framework

Kohana is an elegant PHP framework with a rich set of features for building web applications. It allows to build web applications quickly, as it has many common components included, as translation tools, database access, code profiling, encryption, validation, and more. It also has good debugging and profiling tools which helps to solve any occurring problems, which often is very time consuming without the right tools.

Kohana is built to be a very fast PHP framework, carefully optimized for real world usage. However, some of the tests shown that it is slower than CodeIgniter, and some other major players on the list. But in general, it scores very well on benchmarks.

This is an OOP framework that is very dry. Everything is build using strict PHP 5 classes and objects. This shows that Kohana is sticking to the very best of PHP new features and is closely optimizing its core code.

10. Slim Framework

Slim PHP Framework

Slim framework is designed to be very lightweight, slim. It is a micro-framework that lets you to quickly create simple yet powerful web applications and APIs. It features a powerful router, template rendering with custom views, flash messages, secure cookies with AES-256 encryption, HTTP caching, logging with custom log writers, error handling and debugging, simple configuration.

If you like a framework that is very small and tight, this one is for you. It scores very well on benchmark tests, just falling behind Phalcon, but beating other major players.

11. Fuel PHP

Fuel PHP framework

Fuel is a simple, flexible, community driven PHP 5.3+ framework, baed on the best ideas of other frameworks. It is currently releasing version 2 of the project, currently in beta stage.

FuelPHP is a MVC (Model-View-Controller) framework that was designed from the ground up to have full support for HMVC as part of its architecture. But we didn’t stop there, we also added ViewModels (also known as presentation models) into the mix which give you the option to add a powerful layer between the Controller and the View.

FuelPHP also supports a more router based approach where you might route directly to a closure which deals with the input uri, making the closure the controller and giving it control of further execution.

12. Flight

Flight PHP framework

Flight is an extensive micro framework for PHP. Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications. It requires PHP 5.3+ and is released under the MIT license.

13. Medoo

Medoo PHP framework

I love this micro framework. Medoo is the lightest PHP database framework designed to accelerate development. It is lightweight, only 13 kB in one file. It is extremely easy to learn and use, compatible with various SQL databases, including MySQL, MSSQL, SQLite, MariaDB, Oracle, Sybase, PostgreSQL and more. It is free under the MIT license.

14. PHPixie

PHPixie framework for PHP

PHPixie is a lightweight PHP MVC framework designed to be fast, easy to learn and provide a solid foundation for development. It is very lightweight, well documented, and it makes a lot of use of naming convention so you will need to configure as little as possible.

PHPixie employs a simplistic implementation of the request-response flow yet still enables the use of more complex architectures such as HMVC. PHPixie handles a lot of things differently from the full-stack frameworks. For example, most other frameworks that use an autoloader to load classes force a naming convention. So, you must put classes in folders according to their class names in such a way that a class inside /driver/mysql/query.php should be named Driver_Mysql_Query. PHPixie reverses that order so that the class name becomes Query_Mysql_Driver, resulting in much better readability because the first word of the class name actually describes the class better. This small change can greatly improve the source code presentation of large projects.

15. Pop PHP

Pop PHP framework

The Pop PHP Framework is a robust, yet easy-to-use PHP framework with a verbose API. It supports PHP 5.3+. Today, the Pop PHP Framework maintains its simplicity and is still lightweight. And, even though many new features have been built in, the framework can still easily be used as merely a toolbox, or as a major framework for the foundation of your applications.

16. Simple MVC Framework

Simple MVC Framework

Simple MVC Framework is designed to be extremely easy to setup, have clean coding structure and easy to learn. The framework can be setup just by setting the site path. It features simple theme files, as well as full control over views themes can be used to quickly change the look of your application/website. MySQL is provided using a PDO helper, of course this can be swapped to MySQLI, Medoo or another database engine. Support is provided by a variety of source, Twitter, Facebook Groups and a dedicated Forum. It is lightweight, less than 1 MB size.

Simple MVC Framework seems more promising freedom creativity
Ari Ratic

This is my second framework I use, I have used CI before but SMVCF is much more flexible, lighter (!), The best
Cody

 

17. Typo3 Flow

Typo3 Flow PHP Framework

TYPO3 Flow is a web application platform enabling developers creating excellent web solutions and bring back the joy of coding.

It gives you fast results. It is a reliable foundation for complex applications. And it is backed by one of the biggest PHP communities – TYPO3.

18. Nette

Nette PHP Framework

A popular tool for PHP web development. It is designed to be the most usable as possible and is definitely one of the safest one. It speaks your language and helps you to easily build better websites. Nette uses revolutionary technology that eliminates security holes and their misuse, such as XSS, CSRF, session hijacking, session fixation, etc. It possesses unmatched debug tools, which will help you discover all bugs in timely fashion. Nette is a modern framework, featuring AJAX / AJAJ, Dependency Injection, SEO,DRY, KISS , MVC, Web 2.0, cool URL – a sophisticated support for all advanced technologies and concepts.

19. Agavi

Agavi PHP Framework

Agavi is a powerful, scalable PHP5 application framework that follows the MVC paradigm. It enables developers to write clean, maintainable and extensible code. Agavi puts choice and freedom over limiting conventions, and focuses on sustained quality rather than short-sighted decisions.

20. Silex

Silex PHP Framework

 

Silex is the PHP micro-framework based on the Symfony2 Components.

Silex is a PHP micro-framework for PHP 5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.

A microframework provides the guts for building simple single-file apps. Silex aims to be:

Concise: Silex exposes an intuitive and concise API that is fun to use.
Extensible: Silex has an extension system based around the Pimple micro service-container that makes it even easier to tie in third party libraries.
Testable: Silex uses Symfony2’s HttpKernel which abstracts request and response. This makes it very easy to test apps and the framework itself. It also respects the HTTP specification and encourages its proper use.

Performance benchmark of the best PHP frameworks

There are many assumptions around performance of different PHP frameworks. I frequently hear strong opinions about superiority X over Y in this context. There are companies writing new PHP frameworks from scratch because available solutions are too slow for them. Let’s see what the number are telling.

Performing a representative benchmark across different framework is not an easy task. There are multiple ways to use each of them. Every use case will give different reading. Lets take routing as an example. Zend1 by default doesn’t need a routing file. It’s happy to use “/controller/action” pattern. On the other hand Symfony2 comes with a routing configuration. The file has to be read and parsed. That obviously takes some additional CPU cycles but does it mean Symfony2 routing is slower then Zend1? The answer is (obviously) no.

Systemarchitect has benchmarked “quick start” projects. That gives some idea on what is the base line for every framework and makes it possible to reproduce my tests (and argue against them).
Code was hosted on Amazon EC2 medium instance. I installed PHP-APC to avoid disc access and code parsing. I also made sure there is no I/O on Apache2 or application level. I set logs and cache paths to “/dev/shm/”. I tweaked projects to make them return roughly the same amount of data (10KB). All virtual hosts had the same mod_rewrite rules. AllowOveride was set to None.

Requests per second from Apache Benchmark with c=20 and n=500.

Framework Req/Sec
Phalcon 822.96
Slim 399.83
Kohana 217.34
Code Igniter 187.78
Silex 179.01
Laravel 135.9
YII 123.5
Fuel PHP 116.34
Hazaar MVC 103.53
Zend 1 103.02
Cake PHP 54.97
Nette 53.48
Symfony2 39.22
Zend 2 36.1

 

PHP Benchmark

Based on Systemarchitect’s benchmark, I’m not surprised, Phalcon is beating everyone on the list, as well as seeing Slim to be the second fastest because it’s a micro framework. The Quick Start project didn’t use any templates or layout which obviously contributed to the reading. Zend1 is twice faster than Symfony2 and Zend2 but in my experience the number will quickly go down in a real live setup.

Frameworks should speed up development, performance is a secondary concern. Zend 2 and Symfony2 could do better but it’s not bad. There are ways to improve those numbers on production servers. Don’t reinvent the wheel, learn and use frameworks. There are various options which balance between performance and features.

Editor’s summary

Summarizing the list, I think that the best 5 PHP Frameworks currently are: Laravel, Phalcon, Symfony2, CodeIgniter and Yii.

The same is shown by the recent study at Sitepoint, showing Laravel having over 25% of the popularity votes, Phalcon almost 17%, Symfony2 over 10%, CodeIgniter and Yii having 7.62%.

Sitepoint PHP Framework popularity

 

But we understand that PHP framework is more of a preference for the web developer and that in the market today there are many strong products.

Please tell us your favorite in the comment section below!

Read more

Top 10 WordPress Tesla Themes August 2014

0
  • by vytautas
  • in Themes · Wordpress
  • — 10 Aug, 2014

A business in the age of technology has two faces, a virtual and a physical. A website is the virtual identity of business houses that they maintain while operating in the bigger market in the global atmosphere. Themes are significant in this aspect as they conjure the necessary browsing environment that would welcome the surfers. Business owners will be delighted to learn that shrouding a theme for their website is not a matter of heavy expense, with the feature-rich Tesla themes. One such brilliant WordPress business theme, along with a hosting provider and a domain name equips the developers in launching a fully functional webpage that enhances a business’s customer reach and revenue generation. Described below are the top 10 WordPress Tesla themes that are crisp, responsive, minimalist and worth an investment.

1. Yopta

Yopta Theme

This theme, in a word, is bold and sharp, and highly responsive. The Tesla framework has introduced many new features into this theme that include video support, portfolio of five different versions, Revolution slider and some new portfolio elements.

2. Sevenfold

Sevenfold WordPress Theme

If you are looking for a minimalist theme, the Sevenfold will sure suit your purpose as it has a very clean interface and modern in the real sense of the term. Cyber-friendly, this theme in particular is highly flexible to customization. What’s new? This one has a built-in drag and drop style of form builder and the all new Revolution Slider.

3. Zero

Zero WordPress Theme

Ideally designed for businesses that require a zero-decoration theme and has the element of profession in it, Zero has three landing page representations for something extra for the surfers. To add to that, the theme has a great many transition effects coupled with portfolio element that facilitates showcasing. Other unique features include sticky menu, animated scrolling and font icons.

4. BizNex

BizNex WordPress Theme

Though named BizNex, this one has the design and built suitable for both personal and business portals. Clean and responsive, it has a well-organized layout with a set of beautiful effects and many advanced features that aid both management and navigation. This template is suitable for all small-scale businesses, agencies, corporate events, etc.

5. Display

Display Theme for WordPress

What’s mentionable about this template is that its features are powered by the Telsa Framework, its latest version.

6. Universe

Universe WordPress Theme

This is a theme ideally designed for businesses, having four different homepage representations, custom post options, specially designed image sliders, integrated custom widgets, galleries, etc. Quite a universe in itself, saying that!

7. Zoomy

Zoomy WordPress Theme

This is a photography WordPress theme that has a fresh feel about it, thanks to the transition effects, stylish galleries, sliders, and much more. It is perfect for use by creative agencies, photographers, photo bloggers, and like professionals.

8. Electra

Electra WordPress Theme

This is again a WordPress theme specially designed for businesses. Featuring advanced customization options, this one has special 3D effects, transition effects, animation, drag and drop editors, etc.

9. Design Portfolio

Design Portfolio WordPress Theme

This is another premium theme that has a modern layout and easy customization features. This is noted for easy-to-set-up features. This is ideal for showcasing creative works in a professional, yet stylish manner.

10. Winterfell

Winterfell WordPress Theme

Though designed on the same minimal layout, this one has a creative design and feature-rich interface that makes laying out project works simple, and easy to surf.

Pick themes by their suitability determined by your intended purpose.

The best WordPress Tesla Theme

Please let us know what is your favorite WordPress Tesla Theme in the commen section below. Thanks!

Read more

5 Easy Ways to Add Google Analytics to WordPress

0
  • by vytautas
  • in Wordpress
  • — 9 Aug, 2014

Analyzing visitor traffic in the online world has become evident in order to improve business prospects. With competition in the online platform increasing beyond comprehension, business owners are feeling the necessity of tracking their potential clients and understanding their ever-changing requirements. Fortunately, Google Analytics has offered business owners a way out of this confusion and complication. Therefore, WordPress developers have shown affinity in utilizing these applications to add more features in the service packages. WordPress is popular as a flexible content publishing application. There is more than one way to add Google Analytics to Wordpress; here we are offering information on top 5 ways to get this job done.

1. Google Analyticator

Google Analyticator WordPress Plugin

This plug-in is designed by Ronald Heft and it is considered to be one of the most efficient ways to add GA (Google Analytics) in your WordPress powered site. This plug-in allows the users to check the recent statistics of your site and ‘hit count’ at your convenience. Its dashboard utility allows the administrator to alter or modify the service processes.

Front-end widget, support for latest tracking code, asynchronous tracking, localization, and easy installation are few of the many features of this plug-in.

2. Google Analytics Plug-in

WP Google Analytics plugin

This plug-in has gained recognition as ‘basic process’ for WordPress developers and its ease of usage has gained attention as well. It helps the users to add asynchronous tracking code from the administrative segment. Therefore, enabling or disabling the facilities has become easier.

3. Google Analytics for WordPress

Google Analytics for WordPress plugin

This plug-in is designed by Yoast, and it is considered to be an efficient analytics integrator that provides high level of control over the tracking code. This plug-in comes with various features such as- speed tracking, easy installation process, local hosting support, custom location support of tracking code etc. So, it is safe to sate that this plug-in can be a complete source for controlling the Google Analytics application.

4. Google Analytics Dashboard

Google Analytics Dashboard plugin

Using the dashboard of Google analytics is considered to be very efficient and it can negate the requirement for plug-in usage to implement Google analytics. This process showcases the statistical data of your website and client preference without using GA tracking code. This display acts as the log of your business process.

5. How to Add Google Analytics Code to WordPress Without Plug-In?

WordPress developers and designers can also use tracking-code snippet of their Google Analytics in order to access the statistics and data of websites with ease. Tracking snippet is a fragment of ‘JavaScript’ that allows users to utilize the analytics application from Google. The usage of JavaScript is widely recommended by professionals and experts. Its capability to modify the services and facilities of websites has made it popular in the online world.

In order to use GA tracking code snippet without a plug in, the developers and WordPress administrators need to use your property ID, and use the code snippet in the web pages.

These bits and pieces of information regarding the most popular ways how Google Analytics can be used would help WordPress developers to extract the statistical business growth and client preference data for better business decision.

 

Read more

How to build a fixed menu in WordPress in 3 easy steps

0
  • by vytautas
  • in Wordpress
  • — 8 Aug, 2014

The flexibility of usage and high efficiency level of WordPress have led it to world wide popularity. Its content management capability, continuously improving features, and personalization process has shown promise in bringing life to websites while maintaining their appeal. Building a fixed menu on WordPress platform requires in-depth knowledge of three easy steps.

Navigation Bars in WordPress

Creating a Fixed Menu

The dashboard of the WordPress platform allows the users or operation supervisor authority to modify or alter the work process and design in many ways. Clicking on the ‘Appearance’ section of the dashboard would offer you access to ‘Menus’. Clicking on the ‘Create Menu’ option would initiate the first step of building a fixed menu process. The ‘Create Menu’ button has two sub-sections, viz., Auto add pages and Theme locations.

‘Auto Add Pages’ section allows you to add new pages in an automatic manner in the website. WordPress developers need to uncheck this option in order to follow fixed menu creation.

‘Theme location’ section allows the user to pick out the best location for their newly designed menu. Generally any new menu would locate itself in the navigation area, but if the user’s theme supports multiple navigation processes, then the placement of the new menu can be changed.

Adding Pages and Categories

After deciding the placement for the new menu, the WordPress developers need to initiate the second step of the process, which is to add or select category and page addition. Users would find a list of check boxes in the left hand side of the Dashboard. Checking the preferred boxes and clicking ‘add to menu’ button would allow your new menu to appear with requested and selected options as subsections.

WordPress operators or developers can also enlist categories to create a filtered blog feed, which would navigate through your preferences and allow you to access blog posts for edition. Selecting the check boxes that appear under the category banner and clicking on ‘Add to Menu’ button would complete the second process.

Managing and Sorting Order of the Submenu Elements

As explained previously, Dashboard of the WordPress platform offers the users or the administrators complete access to modify and alter every single element of WordPress site. One of the advantages of using Dashboard is the capability to manage and sort the order of submenus under main menu.

In order to initiate the third and the last step of building a fixed menu process in the WordPress account, the developers or users need to use the tab that displays all the sub menus under the main head. This tab allows the users to create drop-down style menu setup without any complication. Dragging the sub menus under the main menu and nesting to the right side would create the desired effect in the website interface. However, the users would need to click on the ‘save menu’ button after finishing their work, in order to see the changes.

These are three easy yet efficient steps that would lead the efforts of the users towards success in building a fixed menu in WordPress.

 

Read more

How to Manage WordPress comments using SQL

0
  • by vytautas
  • in Wordpress
  • — 7 Aug, 2014

In a bid to combat the comment spamming issue, WordPress developers often choose to use plug-ins. If you want to block spam comments on your WP blog permanently and make way for genuine discussions, you need to know how to bring SQL to play. Here are some handy SQL codes that can help you manage WordPress more efficiently than you can even imagine. You can use PHPMyAdmin, a free-to-use and open-source tool, which can make spam removal and comment management a cakewalk for you. Just do not forget to take a backup of the database before you run SQL+ queries on your server.

How to remove all comments from the server database

Use the below-furnished query to remove all comments marked as ‘spam’ from your database.

DELETE FROM wp_comments WHERE wp_comments.comment_approved = 'spam';

The best part is, the code works perfectly on all WP versions including the most recent, WP 3.9.2!

How to disable/enable comments

In the WP database, under the ‘wp_posts’ table, you can find a column named ‘comment_status’. The column will contain the following values for each post or row.

  • Open (comments are open to every visitor)
  • Closed (comments are closed to every visitor)
  • Registered_only (Comments can only be seen by registered and logged-in users)

You may run the following SQL queries (using phpMyAdmin or any other open source tool which is used in MySQL) to change the default comment-management settingas. (again, do not forget to take backup of your database)

  • For global comment enabling, use UPDATE wp_posts SET comment_status = ‘open’;
  • For global comment enabling, use UPDATE wp_posts SET comment_status = ‘closed’;
  • For global comment enabling for registered users, use UPDATE wp_posts SET comment_status = ‘registered_only’;

For global enabling/disabling comments posted before a certain date, however, you need to specify comment_status and then specify the date as well (default date is 2008-01-01). See an example here:

UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2014-08-06' AND post_status = 'publish';

You may run this query more than once each year for enabling/disabling comments on your old blog posts. You need to combine the code with similar ones for managing trackbacks and pingbacks.

How to enable and disable pingbacks?

You can also find a column named ‘ping_status’ in the wp_posts table. The option can be manipulated for managing pingbacks/trackbacks. Use any of the following values for each post (value).

  • Open (everyone can see pingbacks/trackbacks)
  • Closed (no one can see the pingbacks/trackbacks)

Therefore, you can run the following SQL queries to manipulate the default settings for trackbacks/pingbacks.

UPDATE wp_posts SET ping_status = 'open'; (to enable pingback/trackback for all users)

UPDATE wp_posts SET ping_status = 'closed'; (to disable the same)

UPDATE wp_posts SET ping_status = 'closed' WHERE post_date < '2008-01-01' AND post_status = 'publish'; (change the date if you want to disable/enable pingback/trackback before a certain date)

In this case as well, you can run the query quite a few times each year to change the pingback/trackback settings.

Complete and streamlined comments management

If you know how to make SQL work perfectly, WordPress discussion management is as easy as falling off the log. Use the following ‘one-step’ queries to better manage comments on your blog.

For enabling/disabling all discussions

You need to specify the comment status (as above) and then specify the ping status as well. Example here below:

UPDATE wp_posts SET comment_status = 'open', ping_status = 'open' WHERE comment_status = 'closed' AND post_status = 'publish';

For enabling/disabling all discussions before a date

Specify the comment status and the ping status, and then specify the date. Here, an example for you.

UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE post_date < '2008-01-01' AND post_status = 'publish';

SQL, if used properly, can be highly instrumental in WordPress Comment Management. Try SQL language for yourself and you would know why WordPress developers have so much love for this database language.

Read more

10 Handy and Reusable jQuery Code Snippets

0
  • by vytautas
  • in jQuery · Wordpress
  • — 6 Aug, 2014

To the volleys of coders and software sentries who swear by single words accompanied with special characters and variegated bracket functions (code snippets), jQuery is almost synonymous to ‘indispensable’. Its ease of use, speed and strength are aggregately reflected in 60% of the top 10 000 websites.

Here is an array of 10+ jQuery code snippets that can come handy and can be used at the coder’s discretion. These snippets are easy to adapt, fun to code and can be used any number of times. Here snips the list.

1. Scroll to top

While this one ranks admirably high on the popularity charts, fact is this is among the most forgotten snippets. Four lines in the code allow users to scroll right to top of the page using a link. As a general norm, the link is placed at the bottom of the page.

$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});

 

2. Import external content

If there is a need to import content from an external destination to a particular division, the following jQuery snippet can be used and reused if needed.

$("#content").load("somefile.html", function(response, status, xhr) {
// error handling
if(status == "error") {
$("#content").html("An error occured: " + xhr.status + " " + xhr.statusText);
}
});

 

3. Columns of equal height

If a website displays information in columns, it is for the better to make the columns equal in height. This renders a homogenous feel to the site. The code takes all div elements into consideration. Then, the heights are adjusted with impetus on the bigger elements.

var maxheight = 0;
$("div.col").each(function(){
if($(this).height() > maxheight) { maxheight = $(this).height(); }
});

$("div.col").height(maxheight);

 

4. Partial refresh

If there is a need to refresh only a particular portion of the page, this snippet can more than help. The 3 line code includes a #refresh div that is refreshed automatically once in every 10 seconds.

setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait

 

5. Table Stripes (Zebra pattern)

Tabular data can be made more pleasing to the eye by varying the colors across rows. The following snippet automatically adds a CSS class to every alternative row.

$(document).ready(function(){
$("table tr:even").addClass('stripe');
});

 

6. New tab for external links

The attribute target=”blank” allows the external links to be forced open in a new window or tab. While it is relevant to open some external links in a new window or tab, there are some links that should be necessarily opened in the parent window. The code automatically detects if a link is external. If positively tested, the target=”blank” attribute is assigned to such links.

$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});

 

7. Preload images

With jQuery images can be easily preloaded in the background. This means that visitors will not need to waste a lot of time if they want an image to be displayed. This code can be readily used. A minor update would be needed in line 8 for the image list.

$.preloadImages = function() {
for(var i = 0; i<arguments.length; i++) {
$("<img />").attr("src", arguments[i]);
}
}

$(document).ready(function() {
$.preloadImages("hoverimage1.jpg","hoverimage2.jpg");
});

 

8. Password strength test

If a website allows users to define their own passwords, it is a positive sign if the site also indicates the strength of the entered password. This snippet allows the same. Here is a test HTML:

<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>

 

Following is the jQuery code that will evaluate the strength of the user password. A subsequent message display indicates if the password is weak, medium or strong. Additionally, it also indicates if the length of the password is too short.

$('#pass').keyup(function(e) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$('#passstrength').html('More Characters');
} else if (strongRegex.test($(this).val())) {
$('#passstrength').className = 'ok';
$('#passstrength').html('Strong!');
} else if (mediumRegex.test($(this).val())) {
$('#passstrength').className = 'alert';
$('#passstrength').html('Medium!');
} else {
$('#passstrength').className = 'error';
$('#passstrength').html('Weak!');
}
return true;
});

 

9. jQuery image resizing

While it is safer to resize the image on the other side of the server, knowing how to do so with jQuery can be a huge plus at times. The following snippet takes care of the same.

$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();

if(width > maxWidth){
ratio = maxWidth / width;
$(this).css("width", maxWidth);
$(this).css("height", height * ratio);
height = height * ratio;
}
var width = $(this).width();
var height = $(this).height();
if(height > maxHeight){
ratio = maxHeight / height;
$(this).css("height", maxHeight);
$(this).css("width", width * ratio);
width = width * ratio;
}
});
//$("#contentpage img").show();
// IMAGE RESIZE
});

 

10. Load content on scroll

There are some websites that load content automatically with the user scrolling down. While such a design is generally used in Social media Sites, other commercial sites are also replicating it. The following snippet does the hard work.

var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
loading = false;
});
}
}
});

$(document).ready(function() {
$('#loaded_max').val(50);
});

Read more
  • Categories

    • jQuery
    • PHP
    • Themes
    • Wordpress
  • Home
  • Author: vytautas

© Copyright 2021 Techcoholic. Typegrid Theme by WPBandit.