Magento Engineer
social
Journal

Programming Blogs to Improve Your Coding Skills!

The industry's top wizards and other experts share their advice and research findings.

How to remove .html and .php extensions from URL ?

Write this code to your htaccess file .

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /

# Add trailing slash to url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
  RewriteRule ^(.*)$ $1/ [R=301,L]

# Remove .php-extension from url
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^([^\.]+)/$ $1.php

# End of Apache Rewrite Rules
 </IfModule>

It only removes .php extension, if you want to remove other extension as well (e.g. .html), copy and paste 3rd block and replace php with other extension.
Don't forget to also remove extension from href anchors (links) .

Ad comes here

How to register custom post type in Wordpress ?

Write this code in your function.php file.

function my_custom_post_homepage() {
    $labels = array(
        'name'               => _x( 'Homepage', 'post type general name' ),
        'singular_name'      => _x( 'Homepage', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'news' ),
        'add_new_item'       => __( 'Add New Homepage' ),
        'edit_item'          => __( 'Edit Homepage' ),
        'new_item'           => __( 'New Homepage' ),
        'all_items'          => __( 'All Homepage' ),
        'view_item'          => __( 'View Homepage' ),
        'search_items'       => __( 'Search Homepage' ),
        'not_found'          => __( 'No homepage found' ),
        'not_found_in_trash' => __( 'No homepage found in the Trash' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'Homepage'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our homepage specific data',
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
    );
    register_post_type( 'homepage', $args );    
}
add_action( 'init', 'my_custom_post_homepage' );



<p>Add this code where you want to show custom posts</p>

<div id="custompst">                
<?php query_posts( 'post_type=homepage'); ?>        
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>                    
<li><a href="<?php the_permalink(); ?>" rel="bookmark"><h1 class="adsnameleft"><?php the_title(); ?></h1></a></li>
<li><span class="date"><?php the_time(get_option('date_format')); ?></span></li>                    
<div class="custom-post-entry">
<?php the_content();?>
<div class="clear"></div>                    
</div><!--post-entry end-->
<?php endwhile; ?>
</div> <!--custompst end-->


<p>Add your css for custom posts </p>

#custompst{
    
    width:500px;
    height:auto;
    float:left;
    margin-top:15px;
}
.custom-post-entry{
    
    width:400px;
    height:auto;
    float:left;
}
.adsnameleft{
    background: none repeat scroll 0 0 rgb(185, 185, 185);
    width:400px;

Ad comes here

How to reindex magento2 in XAMPP localhost ?

reindex magento2 in XAMPP localhost

Step1- Open your xampp control panel
step2- Goto Shell command panel
STEP3- open you computer drive where your project is install.

CD "YOUR DRIVE"
CD "YOUR XAMPP FOLDER"
write a command

STEP4- go to in "cd php"

STEP5-Now write this command

php d:\xampp\htodcs\"projectname"\bin\magento indexer:reindex

Ad comes here

How to check php email is working or not on the server?

<?php
$to = "to@youremail.com";
$subject = "Test email";
$message = "This is a test email.";
$from = "from@youremail.com";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
    echo("Your message has been sent successfully");
    } else {
    echo("Sorry, your message could not be sent");
}
?>

Ad comes here

How many type of Inheritance in php ? And, Is multiple Inheritance support PHP?

Inheritance has three types, single, multiple and multi level inheritance. But, PHP supports only single inheritance, where, only one class can be derived from single parent class.

Even though, PHP is not supporting any other inheritance type except single inheritance, we can simulate multiple inheritance by using PHP interface.

In PHP, inheritance can be done by using extends keyword, meaning that, we are extending the derived class with some additional properties and methods of its parent class. The syntax for inheriting a class is as follows.

Child_class_name extends Parent_class_name{
...
.......
}

Ad comes here
Error's and solution's
Update Cookies Preferences