Monday, March 25, 2013

How To Add HTML Links To Standard Prestashop E-Mail Messages

How To Add HTML Links To Standard Prestashop E-Mail Messages


Standard Prestashop order messages section settings do not allow us creating messages which would contain HTML links with clickable anchor texts. But if you want that feature there is still a workaround which you can use to add HTML links to your e-mail messages.

To do this it is necessary to override the method AdminOrderController.php PostProcess as follows:
$customer_message->message = htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8');


Change to
$customer_message->message = Tools::getValue('message');

How To Put Prestashop Category List In Alphabetical Order

How To Put Prestashop Category List In Alphabetical Order

In prestashop when new categories are added to the multi-level navigation blocks, they are placed at the end position of the list which makes it look quite messy. So to sort all the categories in alphabetical order we need to do the following:

In the file modules/blocklayered/blocklayered.php change this line:
GROUP BY c.id_category ORDER BY c.nleft, c.position';

To this one:
GROUP BY c.id_category ORDER BY cl.name ASC, c.nleft, c.position';


Thursday, March 21, 2013

Dynamic Copyright Date in WordPress Footer

Dynamic Copyright Date in WordPress Footer

Sometimes you will will see various websites with outdated copyright dates. Some of the websites show the current year as their copyright date. This is not a very good sign for a website.To give your users a little background information about your website, you should display the copyright date like: © 2010 – 2012. You can do this by just pasting the following code:


function updated_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}




Once you haveadd this function, now open your footer.php file in theme folder  add the following code in the footer or wherever you want to display the dynamic copyright date:
  <?php echo updated_copyright(); ?>

This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.


Change the Footer in WordPress Admin Panel

Change the Footer in WordPress Admin Panel

In the following way ,you can change the footer of your wordPress themes by adding the following guideline. You need to just paste the following code:

function remove_footer_admin () {
echo 'Powered by <a href="http://www.sandipdas.in" target="_blank">Sandip Das</a> | Designed by <a href="http://php-mysql-guide.blogspot.com/" target="_blank">PHP MYSQL GUIDE</a></p>';
}

add_filter('admin_footer_text', 'remove_footer_admin');




Wednesday, March 20, 2013

How to redirect users to a random post

How to redirect users to a random post


To do this follow the instruction below
Create a new file and name it page-random.php and just paste the code below in it:

// set arguments for get_posts()
$args = array(
    'numberposts' => 1,
    'orderby' => 'rand'
);

// get a random post from the database
$my_random_post = get_posts ( $args );

// process the database request through a foreach loop
foreach ( $my_random_post as $post ) {
  // redirect the user to the random post
  wp_redirect ( get_permalink ( $post->ID ) );
  exit;
}

Now, upload the page-random.php file to your wordpress theme directory. After upload login to your WP dashboard and create a new page, called "random" [If you dont call it random, otherwise, the standard page layout will apply, you can check Wordpress Codex for more details about page hierarchy].

Now after you published the random page, if any user  visit the http://www.website.com/random page, he will be automatically redirected to a random post.


How to only display the author posts in the admin post list

How to only display the author posts in the admin post list

In a multi-author blog, the code is very useful to allow each author to only see his own posts in the wordpress admin post list. The following is a simple code snippet to do it.

So you have to paste the code below into the theme functions.php file. Now saved the file, and then authors will only see only their own posts in the admin post list.

<?php

function mypo_parse_query_adminonly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
        if ( !current_user_can( 'level_10' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}

add_filter('parse_query', 'mypo_parse_query_adminonly' );

?>


Thursday, March 14, 2013

How to run the loop outside of WordPress

How to run the loop outside of WordPress

If you need to access your WordPress content and need to run a loop OUTSIDE of your WORDPRESS install? The following code snippet can allow you to run a WordPress loop on any PHP file, or even outside of your WordPress install.



So just paste the following code on any PHP file where you want to run your WordPress loop for accessing data. So for this you need to modify the following:

line 4: Please specify the path to your WordPress wp-blog-header.php file.
line 5: Query posts using the query_posts() function.

<?php
  // Include WordPress
  define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
  query_posts('posts_per_page=1');
?>

<?php while (have_posts()): the_post(); ?>
   <h2><?php the_title(); ?></h2>
   <?php the_excerpt(); ?>
   <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
<?php endwhile; ?>


Tuesday, March 12, 2013

How to save bandwidth and reduce server load

How to save bandwidth and reduce server load

1. Use CSS instead of images
2. Always make sure that your images are optimized
3. Use a cache on your website
4. Prevent bandwidth stealing and hotlinking
5. Use Minify to compress CSS and JavaScript files
6. Use hosting websites to host big files
7. Use GZip compression on your PHP files
8. Use a reliable web hosting

Image resizing using jQuery

Image resizing using jQuery

Example of  jquery fixed image resize


$(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
});
 
 
Source: http://snipplr.com/view/62552/mage-resize/ 


Monday, March 11, 2013

How to make WordPress images responsive

How to make WordPress images responsive

The responsive images can be big on wide screens but automatically adapt to smaller screens such as iphone,iPad. Very easily you can make images responsive. Just follow the simple steps on your blog.


First you have to create the shortcode. Open your functions.php file and paste the following php code in it:

function responsive_images($atts, $content = null) {
     return '<div class="image-resized">' . $content .'</div>';
}

add_shortcode('responsive', 'responsive_images');

Now after that open your style.css file and add those CSS rules:

@media only screen and (max-width:767px) {
    .image-resized img {
        width:100%;
        height:auto;
    }
}

So now you can use the [responsive] shortcode to insert responsive images in your wordpress blog:

[responsive]<img src="image_url" alt="alt" title="title" />[/responsive]

Sql query to delete orphaned post meta from WordPress database

Sql query to delete orphaned post meta from WordPress database

WordPress blog contain thousands of rows of useless meta data. The following simple SQL query can delete orphaned post meta on our database.


You have to just run the following sql query on the WordPress database which delete orphaned post meta.
Before you start, create a backup of your database!

DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off