Category Archives: Wordpress

Custom Taxonomy permalink

Add this coding into theme functions.php.
Change the permalink by replacing the custom_taxonomy_name to your desired custom taxonomy name.
Also Change default_custom_taxonomy_name with the default custom taxonomy term.
add_filter('post_link', 'custom_taxonomy_name_permalink', 10, 3);
add_filter('post_type_link', 'custom_taxonomy_name_permalink', 10, 3);
function custom_taxonomy_name_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%custom_taxonomy_name%') === FALSE) return $permalink;
$post = get_post($post_id);
if (!$post) return $permalink;
$terms = wp_get_object_terms($post->ID, 'custom_taxonomy_name');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'default_custom_taxonomy_name';
return str_replace('%custom_taxonomy_name%', $taxonomy_slug, $permalink);
}

then set custom Permalink structure as shown below
Replace custom_taxonomy_name by your custom taxonomy name.
/%custom_taxonomy_name%/%postname%/

Rate your post without wordpress plugin.

Simple way to Rate your post without wordpress plugin

in single post insert the code below.

<form method='POST' action="">
<input type=hidden name=rate value=up>
<input type=submit value=submit>
</form>

<?php if(isset($_POST['rate'])) { if($_POST['rate']=='up') { $rate=get_post_meta($post->ID,'up',true); $rate=$rate+1; update_post_meta($post->ID,'up',$rate); } if($_POST['rate']=='down') { $rate=get_post_meta($post->ID,'down',true); $rate=$rate+1; update_post_meta($post->ID,'down',$rate); } } echo "UP:".get_post_meta($post->ID,'up',true); echo "DOWN:".get_post_meta($post->ID,'down',true); ?>

I hope you will have idea about it.

decorate submit button up and down with some backgound image like thumb down and thumb up image.

to filter top rated post use the query given below.

query_posts('&meta_key=up&orderby=meta_value_num&order=DESC');

Steps to Translate your theme to native language.

  1. Download a gettext file editor like poedit and install it.
  2. Open the English .po file that came with your WordPress theme or plugin with poedit. If you only got a .pot, just rename it to .po and open it in poedit.
  3. Now go through and translate all the text one line at a time in the bottom box.
  4. Then “File” => “Save” to your desktop or a folder on your computer. This will output a filename.po and filename.mo file.

your file may look like this

msgid “”
msgstr “”
“Project-Id-Version: Arras Theme 1.4\n”
“Report-Msgid-Bugs-To: \n”
“POT-Creation-Date: 2010-03-14 01:12+0800\n”
“PO-Revision-Date: \n”
“Last-Translator: Praveen \n”
“Language-Team:  \n”
“MIME-Version: 1.0\n”
“Content-Type: text/plain; charset=UTF-8\n”
“Content-Transfer-Encoding: 8bit\n”
“X-Poedit-Language: English\n”
“X-Poedit-Country: SINGAPORE\n”
“X-Poedit-SourceCharset: utf-8\n”
“X-Poedit-KeywordsList: _e;__\n”
“X-Poedit-Basepath: .\n”
“X-Poedit-SearchPath-0: ..\n”

#: ../404.php:7
msgid “Error 404 – Not Found”
msgstr “”

#: ../404.php:9
msgid “”
“<p><strong>We’re very sorry, but that page doesn’t exist or has been moved.</strong><br />\n”
“\t\tPlease make sure you have the right URL.</p>\n”
“\t\t<p>If you still can’t find what you’re looking for, try using the search form below.<br />”
msgstr “”

#: ../archive.php:10
#: ../archive.php:12
#, php-format
msgid “%s Archive”
msgstr “”

#: ../archive.php:14
#: ../archive.php:16
#: ../archive.php:18
#, php-format
msgid “Archive for %s”
msgstr “”

put those file into your theme folder.

edit function.php as follows.

<?php load_theme_textdomain(‘theme_name’); ?>

replace theme_name as your wish and use the same below.

you may seen like this in your theme or plugin.

replace theme_name as your wish where ever you use.

<?php _e(‘message’,’theme_name’) ?>

You will need to make a change your WordPress wp-config.php file (located in your WP root directory) with the correct language codes like the example below. If you don’t have a WPLANG entry then create one.

define (‘WPLANG’, ‘filename’);

replace filename by your saved file name alone

Popular posts

php query_posts($query_string.'&posts_per_page=5&meta_key=views&orderby=meta_value_num&order=DESC');
if (have_posts()) : while (have_posts()) : the_post();
<!--  your work here -->
endwhile;
endif;
?>

Google Buzz Followers

// <![CDATA[javascript" charset="utf-8">]]>

function f(result) {

document.getElementById('count').textContent =

result.data.totalResults;

}

</script>

// <![CDATA[src="]]>https://www.googleapis.com/buzz/v1/people/Your_userID/@groups/@followers?max-results=0&alt=json&callback=f"></script>+ Followers</span>

you have to create profile under the url http://www.google.com/profiles
then give the google user Id in the link inside script

Twitter Followers Count

php
function tcount( $username, $field, $display = false ) {
$interval = 3600;
$cache = get_option('tcount');
$url = 'http://api.twitter.com/1/users/show.json?screen_name='.urlencode($username);
if ( false == $cache )
$cache = array();
if ( !isset( $cache[$username][$field] ) ) {
$cache[$username][$field] = NULL;
$cache[$username]['lastcheck'] = 0;
}
if( $cache[$username]['lastcheck'] $value)
if( isset($data->$key) )
$cache[$username][$key] = $data->$key;
$cache[$username]['lastcheck'] = time();
}
else {
$cache[$username]['lastcheck'] = time()+60;
}
update_option( 'tcount , $cache );
}
if ( false != $display )
echo $cache[$username][$field];
return $cache[$username][$field];
}
?>

To Display Twitter Count Use Code Below

echo tcount(“Your_twitter_user_name”,”followers_count”);

 

Face Book Fan Count

Have to download facebook.php file into theme folder.
Get file from following url http://github.com/facebook/php-sdk/raw/master/src/facebook.php

<?php 
require_once('facebook.php'); 
$facebook = new Facebook(array(
'155396374496007',
'secret' => '33a5523fa4fdeecb2e5c29d55afc9627',
'cookie' => true,
));
$result = $facebook->api(array(
'method' => 'fql.query',
'query' => 'select fan_count from page where page_id = give_ur_page_ID_here;'
));
$fb_fans = $result[0]['fan_count'];
?>

To Display facebook fans Count Use Code Below

echo $fb_fans;

 

Site status for wordpress users using wordpress.com stats

If you installed wordpress.com stats plugin you can easily bring your site visitor status to front page. Copy the code below and paste where ever you wants to show.

php
$post_stats = null;
$views=0;
if ( function_exists('stats_get_csv') )
{
global $post_views;
$post_stats = stats_get_csv('postviews', 'days=-1&limit=-1&summarize');
foreach($post_stats as $posts)
{
$views+=$posts['views'];
}
echo "Visitors:".$views;
}
?>

Design a site like this with WordPress.com
Get started