Pages

Wednesday, March 26, 2014

file_get_contents not working with utf8 - [resolved]

If you want to encode special characters from "file_get_contents" than please write below code:

$stringCnt = file_get_contents("URL");
$stringCnt = mb_convert_encoding($stringCnt, 'UTF-8', mb_detect_encoding($stringCnt, 'UTF-8, ISO-8859-1', true));

You can encode "¡ÅѺ˹éÒáá¾ÃФÑÁÀÕÃìÀÒÉÒä·Â©ºÑº" characters.

And If you are using other language than you have to use other encoding method.

Tuesday, March 25, 2014

Highlight search tag on search result page - wordpress[resolved]


You can write below code in your search page:

$title = get_the_title(); 
$keys= explode(" ",$s); 
$title = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="red-bg">\0</span>', $title); 

$excerpt = get_the_excerpt();
$keys = explode(" ",$s);
$excerpt = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="red-bg">\0</span>', $excerpt);



<h2><?php echo $title; ?></h2>
<p><?php echo $excerpt;?></p>

How to set a default taxonomy for custom post types?

Please write below code in functions.php :

add_action( 'save_post', 'set_default_category' );
function set_default_category( $post_id ) {
    // Get the terms
    $terms = wp_get_post_terms( $post_id, 'your_custom_taxonomy');
    // Only set default if no terms are set yet
    if (!$terms) {
        // Assign the default category
        $default_term = get_term_by('name', 'taxonomy_slug', 'your_custom_taxonomy');
        $taxonomy = 'your_custom_taxonomy';
        wp_set_post_terms( $post_id, $default_term->term_id, $taxonomy );
    }
}

Tuesday, March 18, 2014

Redirect when "Error establishing a database connection" - Wordpress

If you want to redirect your website when you got "Error establishing a database connection" than please follow below way:

1. Create one page in "wp-content" directory with "db-error.php" name.
2. Now write your redirection code to this file.