PurabTech is technical blog for Programmer and Coders
Author: Purab
I am Purab from India, Software development is my profession and teaching is my passion.
Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks.
Purab's Github Repo
Youtube Chanel Video Tutorials
Connect to on LinkedIn
In this article, wordpress tutorial, how to display post count of all wordpress tags. In wordpress post we use post tags. For SEO purpose we can show post tags.
how to display post count of all wordpress tags
If we want to show the post count related to wordpress tags.
You can use following code:
<?php
//list all tags that are assigned to posts
$taxonomy = 'post_tag';
$terms = get_terms( $taxonomy, '' );
if ($terms) {
foreach($terms as $term) {
if ($term->count > 0) {
echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
}
}
}
?>
WordPress tutorial for, How to get page id by slug wordpress theme. First find the page id using page title or page page slug. we given sample code here.
Jquery lightbox is mostly used for slideshows in web based project. In wordpress that is most favorite. Here I collected some nice wordpress lightbox plugins.
Lightbox Plus ColorBox implements ColorBox as a lightbox image overlay tool for WordPress. ColorBox was created by Jack Moore and is licensed under the MIT License. Lightbox Plus ColorBox for WordPress implements ColorBox as a lightbox image overlay tool for WordPress. ColorBox was created by Jack Moore and is licensed under the MIT License. Lightbox Plus ColorBox permits users to view larger versions of images without having to leave the current page. Lightbox is able to add a lightbox to WordPress gallery images, display simple slide shows, video, forms and external content in overlays. The use of the dark or light background, which dims the page over which the image has been overlaid, also serves to highlight the image or video being viewed. Lightbox Plus ColorBox captures the image title for display in the overlay.
The next generation of Simple Lightbox is here and ready for brave beta testers. Sign up for SLB 2.0 beta now while there’s still space available!
Simple Lightbox is a very simple and highly customizable lightbox that is easy to add to your WordPress website. It also supports skins, so it can be fully integrated with your site’s theme.
From 2.1, the default view changed to Colorbox due to the license regulation by the plugin directory. This plugin used to add the lightbox (overlay) effect to the current page images on your WordPress blog. Used to overlay images on the current page. Extension of wp-jquery-lightbox.
Just install and sit back. This plugin enable image overlay lighbox effect for all the post images in your wordpress plugin. No configuration required.
This plugin lets you keep the awesome Lightbox 2-functionality, but sheds the bulk of the Prototype Framework and Scriptaculous Effects Library.
Warren Krewenki ported Lightbox to jQuery and this plugin is mostly a wrapper to his work: providing localization support, an admin panel for configuration, (optional) auto-boxing of your image links and support for WordPress galleries, including media library titles and captions.
the default view changed to Colorbox due to the license regulation by the plugin directory. If you would prefer the prior Lightbox to Colorbox, you need to get the script from the setting page.
Clifton’s Lightbox implements a lightbox subscription form overlay. Features a title, list, call-to-action, and image or YouTube video. Users can embed their subscription form into the lightbox and use the call-to-action area to encourage new subscribers.
Clifton’s Lightbox Demo
http://cliftonhatfield.com/cliftons-lightbox/
This plugin allows you to create a lightbox popup with custom contents. You can customize the popup display by configuring various settings such as position settings (height, width, top,left), display logic settings (time delay after page load, number of pages to browse, lightbox repeat interval) and style settings(z-index, overlay opacity, color, border etc). You can use the plugin to display any type of contents such as special promotions, subscription forms, social media icons, feedback forms, video presentations and much more.
Makes the native WordPress galleries use a lightbox script called ColorBox to display the fullsize images right there in the page. No modifications required.
Frndzk photo lightbox plugin adds lightbox effect to all photos of every post and pages. it also shows photos in a group of a post like a photo album. it has next and previous to navigate photos. Just install the plugin and see your photos! no setup or configuration needed
demo
http://bitto.us/wp/fpgdemo
There are people who are struggling for showing PDF file in there wordpress post. Please use following steps for show pdf in post wordpress.
show pdf in post wordpress
1) Go to media -> Add New, upload a file. Once file is uploaded, you will get File URL. Copy that file URL. (Let me call it MY_PDF_URL)
This will be a complete URL, with http://yourdomain.com in it..
2) Now, go to add new post and switch to html editor. Place this code where you want to show the pdf file….
[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]
<embed src="MY_PDF_URL" width="600" height="400">
This will work smoothly. OR you can use following code as well.
GroupDocs Annotation lets you embed several types of files into your WordPress pages using the GroupDocs Viewer – allowing inline viewing and annotation of the following file types, with no Flash or PDF browser plug-ins required:
Adobe Acrobat (PDF)
Microsoft Word (DOC/DOCX)
Microsoft Excel (XLS/XLSX)
Microsoft PowerPoint (PPT/PPTX)
GroupDocs Annotation lets you view and comment on documents online. Its document annotation features makes it a powerful tool for collaboration. You and your colleagues can collaborate on a document, at the same time, to improve communication and speed up document reviews. GroupDocs Annotation lets you work with text-based documents as well as images. You can collaborate on layouts, drawings and designs just as effectively as on articles, stories and corporate documents. In short GroupDocs Annotation lets you annotate on many file formats including PDF’s, Word documents, Excel documents, Powerpoint documents and many other available formats.
Many wordpress developers want to develop new wordpress plugin for various purpose. We given the List of wordpress plugin development frameworks which useful. If you are looking for some ready-made wordpress plugin development frameworks.
List of wordpress plugin development framework
I found some good plugin frameworks which are helpful for developing the wordpress plugin.
Gives authors of new plugins a leg up on creating a great, easy to
maintain plugin by providing a carefully designed plugin skeleton to build on.
Authors of existing plugins can extract individual components and concepts
for transplantation into their own projects.
JeffreyWay / WordPress-Theme-Options-Page
open source class the project is hosted on github aimed at theme developers, looks nice, haven’t used it. .
helgatheviking / thematic-options-KIA
open source Framework the project is
hosted on github aimed at help developers build options into their thematic child themes , witch was forked for Thematic-options very much up to date.
a commercial solution, packed it features and very easy to use.
devinsays / Options-Framework
open source Framework the project is hosted on github aimed at theme developers , i later learned that is has evolved in to Thematic-options very large scaled project that has lots of features.
and IDE for creating option panels , lots of feature and constantly updated, downside is: it’s not easily integrated in plugins or themes and default options are not an option (up to version 1.1.1).
Many wordpress theme developer use following method for developing the wordpress theme. we given Solution to develop wordpress theme with minimal impact and with minimum coding effort.
Copy the wordpress base theme (like twentytwelve in wordpress 3.5)
Rename the folder and converted index.html of my HTML to index.php for wordpress theme.
Replace style.css with current theme style.css.
Solution to develop wordpress theme with minimal impact
This easy way to creating the new theme or you can use the frameworks like as follows:
http://digcms.com/wordpress-themes/apticus/
At the very minimum, a WordPress Theme consists of two files:
style.css
index.php
Here are some resources for faster theme development
This is very common issue with wordpress websites. Many times we solved (unable to upload images in wordpress) same issue So we written detailed article on same topic. This is very common issue with linux or windows server or computer. When you do the wordpress setup you need to give the write able permission to your wp-content/uploads folder.
If you got the following error: when you upload the image.
“Screen Shot 2013-01-28 at 13.53.32 PM.png” has failed to upload due to an error: Unable to create directory wp-content/uploads/2013/01. Is its parent directory writable by the server?
if you are using windows then right-click the uploads folder and uncheck the is read checkbox. Change ownership of uploads folder. Change owner to apache.
solved: unable to upload images in wordpress
if you are using the linux then use following command:
In wordpress admin users listing page, wordpress admin has user search with username and email but we cannot search via display name or first name and last name.
We can add firstname, lastname and display name in users search. You just need to add following code.
/*
* functions will be applicable for only wordpress admin
*/
if (is_admin()) {
/*
* Modify the User Search in Admin to include firstname, lastname and display_name
*/
add_action('pre_user_query', 'wpapi_pre_user_query');
function wpapi_pre_user_query($user_search) {
//die();
global $wpdb;
// print_r($user_search);
$vars = $user_search->query_vars;
if (!is_null($vars['search'])) {
/* For some reason, the search term is enclosed in asterisks.
Remove them */
$search = preg_replace('/^\*/', '', $vars['search']);
$search = preg_replace('/\*$/', '', $search);
//print_r($search);
//search in display name
if(!empty($search)){
$user_search->query_where = substr(trim($user_search->query_where), 0, -1) . " OR display_name LIKE '%". $search . "%')";
}
$user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON " .
"{$wpdb->users}.ID=m1.user_id AND (m1.meta_key='first_name')";
$user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m2 ON " .
"{$wpdb->users}.ID=m2.user_id AND (m2.meta_key='last_name')";
$names_where = $wpdb->prepare("m1.meta_value LIKE '%s' OR m2.meta_value LIKE '%s'", "%{$search}%", "%$search%");
$user_search->query_where = str_replace('WHERE 1=1 AND (', "WHERE 1=1 AND ({$names_where} OR ", $user_search->query_where);
}
return $user_search;
}
}
wordpress user search firstname lastname and display name code
WordPress tutorial, wordpress WP_Query vs query_posts vs get_posts. There are three ways for fetching data(posts) from wordpress. query_posts more often than others. But I prefer to use WP_Query(). WP_Query is object base more secure then others.
wordpress WP_Query vs query_posts vs get_posts
wordpress WP_Query vs query_posts vs get_posts
query_posts() is overly simplistic and problematic way to to modify main query of page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with pagination). Any modern WP code should use more reliable methods, like making use ofpre_get_posts hook, for this purpose. TL;DR don’t use query_posts() ever;
get_posts() is very similar in usage and accepts same arguments (with some nuances, like different defaults), but returns array of posts, doesn’t modify global variables and is safe to use anywhere;
WP_Query class powers both behind the scenes, but you can also create and work with own object of it. Bit more complex, less restrictions, also safe to use anywhere.
The basic difference is that query_posts() is really only for modifying the current Loop. Once you’re done it’s necessary to reset the loop and send it on its merry way. This method is also a little easier to understand, simply because your “query” is basically a URL string that you pass to the function, like so:
query_posts(‘meta_key=color&meta_value=blue’);
On the other hand, wp_query is more of a general purpose tool, and is more like directly writing MySQL queries than query_posts() is. You can also use it anywhere (not just in the Loop) and it doesn’t interfere with any currently running post queries.
In wordpress theming is very important. Developers know the importance of functions.php file. Here we given most used wordpress functions in theme which will be useful for wordpress developer. I always written some very nice code snippets in functions.php file.
most used wordpress functions in theme
I found very useful codes which is very helpful for very wordpress designer and developers.
Here is very useful code snippets. Enable Hidden Admin Feature displaying ALL Site Settings
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS
function all_settings_link() {
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');
Remove Update Notification for all users except ADMIN User
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN
global $user_login;
get_currentuserinfo();
if (!current_user_can('update_plugins')) { // checks to see if current user can update plugins
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
Include custom post types in the search results.
// MAKE CUSTOM POST TYPES SEARCHABLE
function searchAll( $query ) {
if ( $query->is_search ) { $query->set( 'post_type', array( 'site','plugin', 'theme','person' )); }
return $query;
}
add_filter( 'the_search_query', 'searchAll' );
Add your custom post types to your sites main RSS feed by default.
// ADD CUSTOM POST TYPES TO THE DEFAULT RSS FEED
function custom_feed_request( $vars ) {
if (isset($vars['feed']) && !isset($vars['post_type']))
$vars['post_type'] = array( 'post', 'site', 'plugin', 'theme', 'person' );
return $vars;
}
add_filter( 'request', 'custom_feed_request' );
Modify the Login Logo & Image URL Link
add_filter( 'login_headerurl', 'namespace_login_headerurl' );
/**
* Replaces the login header logo URL
*
* @param $url
*/
function namespace_login_headerurl( $url ) {
$url = home_url( '/' );
return $url;
}
add_filter( 'login_headertitle', 'namespace_login_headertitle' );
/**
* Replaces the login header logo title
*
* @param $title
*/
function namespace_login_headertitle( $title ) {
$title = get_bloginfo( 'name' );
return $title;
}
add_action( 'login_head', 'namespace_login_style' );
/**
* Replaces the login header logo
*/
function namespace_login_style() {
echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>';
}
Loading jQuery from the Google CDN
// even more smart jquery inclusion :)
add_action( 'init', 'jquery_register' );
// register from google and for footer
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ), false, null, true );
wp_enqueue_script( 'jquery' );
}
}
Remove the WordPress Version Info for Security
// remove version info from head and feeds
function complete_version_removal() {
return '';
}
add_filter('the_generator', 'complete_version_removal');
Add Spam & Delete Links to Comments on Front End
// spam & delete links for all versions of wordpress
function delete_comment_link($id) {
if (current_user_can('edit_post')) {
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> ';
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>';
}
}