Tuesday, November 14, 2017

Sunday, November 12, 2017

SSH- Change all files and folders permissions of a directory to 644/755

SSH- Change all files and folders permissions of a directory to 644/755
 
   
find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files



For WordPress -


All files should be 664.
All folders should be 775.
wp-config.php should be 660.
    

Monday, October 30, 2017

SSH- How to create php files in /var/www folder?

SSH- How to create php files in /var/www folder?


-Create the file

sudo touch hello.php

-Open the file

sudo vi hello.php

Enter write mode (we were in command mode initially) by pressing  a  (note that    vi   is case sensitive)

After that, press Esc (to change to command mode) and type :wq Check if everything is fine with
cat hello.php

However, it's probably a better idea to use editors such as vim or nano as work with them is a lot simpler than that.

Wednesday, October 11, 2017

SSH- Useful SSH commands


SSH- Useful SSH commands

1. Access monitor
mysql -u [username] -p; (will prompt for password)
2. Show all databases:
show databases;

3. Access database:
mysql -u [username] -p [database] (will prompt for password)

4.Create new database:
create database [database];

5.Select database:
use [database];

6. Determine what database is in use:
select database();

7. Show all tables:
show tables;

8. Show table structure:
describe [table];


9. List all indexes on a table:
show index from [table];

10. Create new table with columns:
CREATE TABLE [table] ([column] VARCHAR(120), [another-column] DATETIME);

11. Adding a column:
ALTER TABLE [table] ADD COLUMN [column] VARCHAR(120);

12. Adding a column with an unique, auto-incrementing ID:
ALTER TABLE [table] ADD COLUMN [column] int NOT NULL AUTO_INCREMENT PRIMARY KEY;

13. Inserting a record:
INSERT INTO [table] ([column], [column]) VALUES ('[value]', [value]');

14. MySQL function for datetime input:
NOW()

15. Selecting records:
SELECT * FROM [table];

16.Explain records:
EXPLAIN SELECT * FROM [table];

17. Selecting parts of records:
SELECT [column], [another-column] FROM [table];

18. Counting records:
SELECT COUNT([column]) FROM [table];

19.Counting and selecting grouped records:
SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];

20. Delete all records in a table:
truncate table [table];

21. Removing table columns:
ALTER TABLE [table] DROP COLUMN [column];

22. Deleting tables:
DROP TABLE [table];

23.Deleting databases:
DROP DATABASE [database];

24. Custom column output names:
SELECT [column] AS [custom-column] FROM [table];

25.  Export a database dump:
mysqldump -u [username] -p [database] > db_backup.sql


26.  Import a database dump (more info here):
mysql -u [username] -p -h localhost [database] < db_backup.sql

27. Logout:
exit;

SSH- How to export/import a MySQL database via SSH

How to export/import a MySQL database via SSH

USERNAME - the MySQL user assigned to your database.
DATABASE - the name of your MySQL database.

1. Exporting a MySQL database

mysqldump -uUSERNAME -p DATABASE > backup.sql

2. Importing a MySQL database

mysql -uUSERNAME -p DATABASE < backup.sql

Wednesday, September 13, 2017

Wordpress- I want to add pagination list of categories

 <?php   
    $args = array(
   'parent' => 0,
   'hide_empty' => 0
 );

$categories = get_categories( $args );
echo $cat =  ceil(count( $categories )/5);   
 ?>
 <?php
  $j=0;
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $posts_per_page = 5;
$offset = ($posts_per_page * $paged) - 5 ;
$args = array(
'orderby' => 'name',
'parent' => 0,
'hide_empty'         => 0,
'number' => $posts_per_page,
'offset' => $offset,
'posts_per_page' => 5,
'paged' => $paged

//'exclude'            => '1,3,24,9'
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$j++;
 //echo '<a href="' . get_category_link( $category->term_id ) . '">' .       $category->name . '</a><br/>';
 $catname = $category->name;
 $catttid = $category->term_taxonomy_id;
  //}
   ?>

<div class="row"><h3 class="cat-title"><?php echo $catname; ?></h3><hr  class="space" /></div>
  <?php } ?>
  </div></div>
   <!-- #main -->
  </div><!-- #primary -->
  <?php
  $big = 999999999; // need an unlikely integer
    echo '<div class="paginate-links">';
  echo paginate_links( array(
  'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  'format' => '?paged=%#%',
  'prev_text' => __('<<'),
  'next_text' => __('>>'),
  'current' => max( 1, get_query_var('paged') ),
  'total' => $cat
     ) );
echo '</div>';
  ?>

Thursday, August 31, 2017

Magento- Cannot display image inserted by WYSIWYG editor

I finally solved the problem. The cause of the problem is unprocessed shortcodes in the html content, which is the {{ media url="..." }} statement. Before echo this statement, the html content should be process by the processor from helper "cms". Below is the code:


$html_content = $content_from_db['content'];
$html_content = Mage::helper('cms')->getPageTemplateProcessor()->filter($html_content);
echo $html_content;

Wednesday, August 9, 2017

Wordpress- Post Pagination Modifications (wp_link_pages)

Below code will show Next and Previous Links with the page count in between.
<?php

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '',
'next_or_number' => 'next' ) );

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '',
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) );

?>


For infinite loop prev next, w can use below code- 

global $page, $pages;
                 if(count($pages) > 1){
                    
                  
                    
                echo '<div class="middle-pagination page-link-next-prev">';     
                if($page == 1){
                  
                    ?>
                     <a id="next" href="<?php the_permalink();?><?php echo count($pages);?>/" rel="prev">Prev</a>
                    <?php
                }
              
                wp_link_pages( array( 'before' => '',
                'after' => '', 'previouspagelink' => 'Prev', 'nextpagelink' => '',
                'next_or_number' => 'next' ) );

                // This shows the page count i.e. "1 of 5"
                echo '<span class="m-counts">';
                echo( $page.' of '.count($pages) );
                echo '</span>';

                // This shows the Next link
                wp_link_pages( array( 'before' => '', 'after' => '', 'previouspagelink' => '',
                'nextpagelink' => 'Next', 'next_or_number' => 'next' ) );
              
              
                if($page == count($pages)){
                  
                    ?>
                     <a id="next" href="<?php the_permalink();?>" rel="prev">Next</a>
                    <?php
                }
              
                echo '</div>';
              
                 }

Wednesday, July 26, 2017

Woocommerce- Change number or products per row to 3

Woocommerce- Change number or products per row to 3


We can add below filter in functions.php

// Change number or products per row to 3
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
    function loop_columns() {
        return 3; // 3 products per row
    }
}

Tuesday, July 25, 2017

Magento - How to show all products of a category in only one page

Magento - How to show all products of a category in only one page



I have found the solution in Magento backend,

it's like this :

Configuration > catalog > frontend > Allow All Products per Page > yes  :)

Magento- Customer attribute values by attribute ID

Magento- Customer attribute values by attribute ID


 <?php
    $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
    ->setAttributeFilter(161)
    ->load();


    foreach ($valuesCollection as $item) {

    $attr = Mage::getModel('eav/entity_attribute_option')
    ->getCollection()->setStoreFilter()
    ->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code')
    ->addFieldToFilter('main_table.option_id',array('eq'=>$item->getId()))->getFirstItem();
    $procategorydata= $attr->getData();       
    ?>
    <option value="<?php echo $procategorydata['option_id'] ?>"><?php echo $procategorydata['value'] ?></option>
    <?php
    }
    ?>

Saturday, July 1, 2017

Woocommerce- Add custom field to “customer details” block in order email

/**
 * Add custom fields to emails
 */
add_filter('woocommerce_email_customer_details_fields', 'my_checkout_field_order_meta_fields', 40, 3 );
function my_checkout_field_order_meta_fields( $fields, $sent_to_admin, $order ) {
  $fields['custom_field_1'] = array(
    'label' => __( 'Vælg og bekræft din biltype' ),
    'value' => get_post_meta( $order->id, 'Vælg og bekræft din biltype', true ),
  );
  $fields['custom_field_2'] = array(
    'label' => __( 'Afgivet bestilling' ),
    'value' => get_post_meta( $order->id, 'Afgivet bestilling', true ),
  );
 
 
  return $fields;
}

WooCommerce – remove payment method from emails

add_filter( 'woocommerce_get_order_item_totals', 'custom_woocommerce_get_order_item_totals' );

function custom_woocommerce_get_order_item_totals( $totals ) {
  unset( $totals['payment_method'] );
  return $totals;
}