Development – ANJ WebTech https://anjwebtech.com Advancing Your Journery Fri, 05 Mar 2021 07:19:21 +0000 en-US hourly 1 https://wordpress.org/?v=5.4.15 https://anjwebtech.com/wp-content/uploads/2020/07/favicon.png Development – ANJ WebTech https://anjwebtech.com 32 32 Add, Update, Delete and Read JSON Data/File in PHP https://anjwebtech.com/add-update-delete-and-read-json-data-file-in-php/ https://anjwebtech.com/add-update-delete-and-read-json-data-file-in-php/#respond Tue, 05 Jan 2021 05:41:02 +0000 https://anjwebtech.com/?p=4872 Read JSON File in PHP: <?php // load file $data = file_get_contents('results.json'); // decode json to associative array $json_arr = json_decode($data, true); foreach ($json_arr as $key => $value) { echo $json_arr[$key] . " - " . $json_arr[$value] . "<br/>"; } ?> Add to JSON File in PHP: <?php // read […]

The post Add, Update, Delete and Read JSON Data/File in PHP appeared first on ANJ WebTech.

]]>
Read JSON File in PHP:
<?php
// load file
$data = file_get_contents('results.json');

// decode json to associative array
$json_arr = json_decode($data, true);

foreach ($json_arr as $key => $value) {
    echo  $json_arr[$key] . " - " .  $json_arr[$value] . "<br/>";
}
?>

Add to JSON File in PHP:

<?php
// read json file
$data = file_get_contents('results.json');

// decode json
$json_arr = json_decode($data, true);

// add data
$json_arr[] = array('Code'=>4, 'Name'=>'Jeff Darwin', 'Sports'=>'Cricket');

// encode json and save to file
file_put_contents('results_new.json', json_encode($json_arr));
?>

Update JSON File PHP:

<?php
// read file
$data = file_get_contents('results.json');

// decode json to array
$json_arr = json_decode($data, true);

foreach ($json_arr as $key => $value) {
    if ($value['Code'] == '2') {
        $json_arr[$key]['Sports'] = "Foot Ball";
    }
}

// encode array to json and save to file
file_put_contents('results_new.json', json_encode($json_arr));
?>

Delete JSON Data from File:

<?php
// read json file
$data = file_get_contents('results.json');

// decode json to associative array
$json_arr = json_decode($data, true);

// get array index to delete
$arr_index = array();
foreach ($json_arr as $key => $value)
{
    if ($value['Code'] == "2")
    {
        $arr_index[] = $key;
    }
}

// delete data
foreach ($arr_index as $i)
{
    unset($json_arr[$i]);
}

// rebase array
$json_arr = array_values($json_arr);

// encode array to json and save to file
file_put_contents('results_new.json', json_encode($json_arr));
?>

 

The post Add, Update, Delete and Read JSON Data/File in PHP appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/add-update-delete-and-read-json-data-file-in-php/feed/ 0
Javascript Projects [Javascript Examples] https://anjwebtech.com/javascript-projects-javascript-examples/ https://anjwebtech.com/javascript-projects-javascript-examples/#respond Tue, 29 Dec 2020 06:48:36 +0000 https://anjwebtech.com/?p=4879 Why JavaScript Projects? JS is the heart of any web application. Good knowledge of JavaScript can get you a range of challenging and interesting career options like developing mobile and desktop apps, building dynamic websites from scratch, UI/UX designer, or even a full stack developer.If you know the basics of […]

The post Javascript Projects [Javascript Examples] appeared first on ANJ WebTech.

]]>
Why JavaScript Projects?

JS is the heart of any web application. Good knowledge of JavaScript can get you a range of challenging and interesting career options like developing mobile and desktop apps, building dynamic websites from scratch, UI/UX designer, or even a full stack developer.If you know the basics of JavaScript, projects are your next step to add stars to your resume.If you don’t have any prior programming experience, you can take up basic JavaScript courses and then come back to these projects.If you follow a bit of HTML & CSS, you will understand most of the Javascript projects with the source code mentioned below.

1. JavaScript Calculator

<html>
<body>
<div class = title >My Beautiful JS Calculator</div>
<table border=”2″>
<tr>
<td><input type=”button” value=”c” onclick=”clr()”/> </td>
<td colspan=”3″><input type=”text” id=”textval”/></td>
</tr>
<tr>
<td><input type=”button” value=”+” onclick=”display(‘+’)”/> </td>
<td><input type=”button” value=”1″ onclick=”display(‘1’)”/> </td>
<td><input type=”button” value=”2″ onclick=”display(‘2’)”/> </td>
<td><input type=”button” value=”3″ onclick=”display(‘3’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”-” onclick=”display(‘-‘)”/> </td>
<td><input type=”button” value=”4″ onclick=”display(‘4’)”/> </td>
<td><input type=”button” value=”5″ onclick=”display(‘5’)”/> </td>
<td><input type=”button” value=”6″ onclick=”display(‘6’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”*” onclick=”display(‘*’)”/> </td>
<td><input type=”button” value=”7″ onclick=”display(‘7’)”/> </td>
<td><input type=”button” value=”8″ onclick=”display(‘8’)”/> </td>
<td><input type=”button” value=”9″ onclick=”display(‘9’)”/> </td>
</tr>
<tr>
<td><input type=”button” value=”/” onclick=”display(‘/’)”/> </td>
<td><input type=”button” value=”.” onclick=”display(‘.’)”/> </td>
<td><input type=”button” value=”0″ onclick=”display(‘0’)”/> </td>
<td><input type=”button” value=”=” onclick=”evaluate()”/> </td>
</tr>
</table>
</body>
<script>
function display(val)
{
document.getElementById(“textval”).value+=val
}
function evaluate()
{
let x = document.getElementById(“textval”).value
let y = eval(x)
document.getElementById(“textval”).value = y
}
function clr()
{
document.getElementById(“textval”).value = “”
}
</script>
<style>
input[type=”button”] {
border-radius: 10px;
background-color:blue;
color: white;
border-color:#black ;
width:100%;
}
input[type=”text”] {
border-radius: 10px;
text-align: right;
background-color:black;
color: white;
border-color: white;
width:100%
}
</style>
</html>

 

2. Hangman Game
3. Tic Tac Toe Game
4. JavaScript Weather App
5. JavaScript Music Events
6. JavaScript Form Validation

<html>
<head>
<title>Form Validation</title>
<script type = “text/javascript”>
function validateEmail(emailField){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (reg.test(emailField.value) == false) {
alert(‘Invalid Email Address’);
return false;
}
return true;
}
function validate() {
var text;
if( document.myForm.name.value == “” ) {
text = “Name cannot be empty”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.name.focus() ;
return false;
}
if( document.myForm.email.value == “” ) {
text = “E-mail cannot be empty”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.email.focus() ;
return false;
}
var emailID = document.myForm.email.value;
atposn = emailID.indexOf(“@”);
dotposn = emailID.lastIndexOf(“.”);
if (atposn < 1 || ( dotposn – atposn < 2 )) {
text = “Please enter valid email ID”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.email.focus() ;
return false;
}
if( document.myForm.phone.value == “” || isNaN( document.myForm.phone.value ) ||
document.myForm.phone.value.length != 10 ) {
text = “Please enter a valid 10-digit phone number”;
document.getElementById(“demo”).innerHTML = text;
document.myForm.phone.focus() ;
return false;
}
if( document.myForm.subject.value == “0” ) {
text = “Please provide your area of expertise”;
document.getElementById(“demo”).innerHTML = text;
return false;
}
return( true );
}
</script>
</head>
<body>
<form action = “” name = “myForm” onsubmit = “return(validate());”>
<h1 align=”center”>USER REGISTRATION</H1>
<table align=”center” cellspacing = “3” cellpadding = “3” border = “3”>
<tr>
<td align = “right”>Name</td>
<td><input type = “text” name = “name” /></td>
</tr>
<tr>
<td align = “right”>E-mail</td>
<td><input type = “text” name = “email” /></td>
</tr>
<tr>
<td align = “right”>Phone Number</td>
<td><input type = “text” name = “phone” /></td>
</tr>
<tr>
<td align = “right”>Subject</td>
<td>
<select name = “subject”>
<option value = “0” selected>Select</option>
<option value = “1”>HTML</option>
<option value = “2”>JavaScript</option>
<option value = “3”>CSS</option>
<option value = “4”>JSP</option>
</select>
</td>
</tr>
</table>
<p id=”demo” style=”color:red; text-align:center”></p>
<div style=”text-align:center”><input type = “submit” value = “Submit” /></div>
</form>
</body>
</html>

7. JavaScript Photo Details Display
8. Build an Interactive Landing Page
9. Build a Shopping Cart for Order Fulfillment
10. Single Page Application

The post Javascript Projects [Javascript Examples] appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/javascript-projects-javascript-examples/feed/ 0
What Makes Up a PHP Project? https://anjwebtech.com/what-makes-up-a-php-project/ https://anjwebtech.com/what-makes-up-a-php-project/#respond Tue, 03 Nov 2020 07:18:34 +0000 https://anjwebtech.com/?p=4883 What Makes Up a PHP Project? 1. PHP Development Environment/Language Release 2. Development Tools; Editors, IDEs, and Frameworks PHP Code Editors/Text Editors  Atom Brackets Komodo Edit Notepad++ Sublime Text 3 Visual Studio Code PHP IDEs Eclipse Komodo NetBeans PhpStorm Rapid PHP editor Zend Studio 3. Web Server 4. Database Management […]

The post What Makes Up a PHP Project? appeared first on ANJ WebTech.

]]>
What Makes Up a PHP Project?

1. PHP Development Environment/Language Release
2. Development Tools; Editors, IDEs, and Frameworks

  • PHP Code Editors/Text Editors
    1.  Atom
    2. Brackets
    3. Komodo Edit
    4. Notepad++
    5. Sublime Text 3
    6. Visual Studio Code
  • PHP IDEs
    1. Eclipse
    2. Komodo
    3. NetBeans
    4. PhpStorm
    5. Rapid PHP editor
    6. Zend Studio

3. Web Server

4. Database Management System (DBMS)

The post What Makes Up a PHP Project? appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/what-makes-up-a-php-project/feed/ 0
Benefits of Choosing Laravel Framework for Your Next Project https://anjwebtech.com/benefits-of-choosing-laravel-framework-for-your-next-project/ https://anjwebtech.com/benefits-of-choosing-laravel-framework-for-your-next-project/#respond Thu, 06 Aug 2020 10:45:13 +0000 https://anjwebtech.com/?p=4227 “Love beautiful code? We do too.” Laravel framework has taken PhP to new heights. This framework is a newbie to the IT industry, which can be quite daunting, but at the same time it has been fortunate enough in attracting a lot of users. In the more technical terms: Laravel, […]

The post Benefits of Choosing Laravel Framework for Your Next Project appeared first on ANJ WebTech.

]]>

“Love beautiful code? We do too.”

Laravel framework has taken PhP to new heights. This framework is a newbie to the IT industry, which can be quite daunting, but at the same time it has been fortunate enough in attracting a lot of users. In the more technical terms:

Laravel, a PHP framework, is an open-source toolbox that aids in developing high-end applications.

mvc diagram with routes

1. Highly Secured
2. Authorization and Authentication systems creation
3. Integration with Mail Services
4. Reduce Manual Effort & Cost
5. Tools Integration for Agile Development
6. Fixing Technical Vulnerabilities
7. Traffic Handling
8. Inbuilt Libraries
9. URL Generations
10. Artisan Tool for Command Line
11. Fine Unit Testing

Laravel is popular because:

  • Tasks that typically take hours and hundreds of lines of code to write can be performed with pre-built functions within few minutes with Laravel framework. For instance, cache (to enhance performance), authentication (social login integration) etc. are already instituted in Laravel’s new installation which makes the development easier, faster and more efficient!
  • Writing unit tests is a time – consuming task, but the effort spent is definitely worthwhile because software testing provides product or service quality information to customers. Laravel testing is, fortunately, already integrated into the framework!
  • Developers don’t have to spend too much time analyzing best practices in developing and maintaining web applications and taking decisions on how to properly implement everything because the documentation in Laravel framework is detailed. You can find various courses, code snippets, tutorials on Laravel. Unlike other frameworks, Laravel framework is pleasing and welcoming.

The post Benefits of Choosing Laravel Framework for Your Next Project appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/benefits-of-choosing-laravel-framework-for-your-next-project/feed/ 0
How to Create a Testimonials Plugin https://anjwebtech.com/how-to-create-a-testimonials-plugin/ https://anjwebtech.com/how-to-create-a-testimonials-plugin/#respond Fri, 31 Jul 2020 08:08:27 +0000 https://anjwebtech.com/?p=4138 The Basics As we’ve said before, you’ll need to add the header metadata, create the plugin file and call your scripts. Long story short, you’ll create a new folder under your wp-content/plugins with your plugin’s name, then create a file with the same name as the folder to be your main […]

The post How to Create a Testimonials Plugin appeared first on ANJ WebTech.

]]>

The Basics

As we’ve said before, you’ll need to add the header metadata, create the plugin file and call your scripts. Long story short, you’ll create a new folder under your wp-content/plugins with your plugin’s name, then create a file with the same name as the folder to be your main plugin file.

Once you’ve done that copy and paste as follows:

<?php
/*
Plugin Name: Testimonials
Description: Display customer testimonials.
Version: 1.0
Author: Web Revenue Blog
License: GPL2
*/

//enqueueing scripts and styles
function plugin_scripts(){
    wp_enqueue_script('jquery');
    wp_enqueue_script('flexslider', plugins_url( 'js/jquery.flexslider-min.js' , __FILE__ ), array('jquery'), '2.2', false);
    wp_enqueue_script('testimonials', plugins_url( 'js/testimonials.js' , __FILE__ ), array('jquery'), '1.0', false);
    wp_enqueue_style('flexsliderCSS', plugins_url( 'css/flexslider.css' , __FILE__ ), false, '2.2', 'all' );
    wp_enqueue_style('testimonialsCSS', plugins_url( 'css/testimonials.css' , __FILE__ ), false, '1.0', 'all' );
}
add_action("wp_enqueue_scripts","plugin_scripts");

Here is what we’re doing:

  • Telling to the WP what’s our plugin’s name, author, what it does
  • Creating a function, where we insert regular scripts (like jQuery) and custom scripts (like flexslider), and Stylesheets
  • Telling to the WP to load the scripts function in its default scripts call, so they’ll be actually loaded in the pages

It’s all pretty cool, but don’t forget to actually create the files under /js and /css. You can just download them in our demo content so you don’t need to dig a lot to find the flexslider files.

Now we have all basic things in place we can start the funny part.

The Custom Post Type

By default, WordPress have 2 common post types, pages and posts. But it also has a lot of internal post types (like attachments), so the “post type” definition is: Every type of data you need to store.

As our plugin will create a new functionality WP doesn’t have a built-in place to store that, so we need to create that. Don’t be afraid little grasshopper, it’s quite simple, you can use this code:

//the black magic to create the post type
function create_post_type() {
    register_post_type(
        'testimonials',//new post type
        array(
            'labels' => array(
                'name' => __( 'Testimonials' ),
                'singular_name' => __( 'Testimonial' )
            ),
            'public' => true,/*Post type is intended for public use. This includes on the front end and in wp-admin. */
            'supports' => array('title','editor','thumbnail','custom_fields'),
            'hierarchical' => false
        )
    );    
}

Here we’re just using the register_post_type() function to tell to WP “Hey Buddy, we need to store this kind of data, please be ready to receive it”.

We also tell him that this kind of data is called “testimonials”, it should be available for public access (so it actually create a new menu item in your dashboard for it), the fields that we need on it, and if it’s hierarchical or not (like pages that we have parent and child pages).

Then we need to call it every time we load WordPress. This hook will do it:

add_action( 'init', 'create_post_type' );

The Custom Fields

Now our custom post type have the title (person’s name), the content (person’s testimonial), a picture (featured image) but it’s missing a link, since if the person is nice enough to talk about you, you should at least link to their site, right?

We could do this with usual custom fields, but it’s much better to have a “closed” field, where the user doesn’t need to type field’s name, and also where you can add some validation rules.

First of all we need to create a new metabox, which is those nice panels you have in your post edit area, each little panel is a metabox. This function will create and call it:

//adding the URL meta box field
function add_custom_metabox() {
    add_meta_box( 'custom-metabox', __( 'Link' ), 'url_custom_metabox', 'testimonials', 'side', 'low' );
}
add_action( 'admin_init', 'add_custom_metabox' );

The add_meta_box() function requires these parameters:

  1. ID – The unique identifier for it. You could use anything unique here like “unicorn-eating-rainbow” or “testimonial-link”. Anything that can be used internally
  2. Title – What will be shown for the user? Here it’s important to use the __() function, it’s the function that allow users from foreign languages to translate your plugin with .po files (without editing plugin files)
  3. Callback – The function where you have the actual contents of the metabox
  4. Post Type – In our case we want it to be visible only for testimonials
  5. Context – Where in the page you want to show it
  6. Priority – If it should be before other items of the same position or after them

Now we need to create the url_custom_metabox() function, since we’ve called it.

// HTML for the admin area
function url_custom_metabox() {
    global $post;
    $urllink = get_post_meta( $post->ID, 'urllink', true );

    //validating!
    if ( ! preg_match( "/http(s?):///", $urllink ) && $urllink != "") {
        $errors = "This URL isn't valid";
        $urllink = "http://";
    } 

    // output invlid url message and add the http:// to the input field
    if( isset($errors) ) { echo $errors; }
?>    
<p>
    <label for="siteurl">URL:<br />
        <input id="siteurl" size="37" name="siteurl" value="<?php if( isset($urllink) ) { echo $urllink; } ?>" />
    </label>
</p>
<?php
}

Ok, now translating this to plain English:

  • The global variable $post is called, so we can know which is the POSTID of the current item
  • We load the current value for the URL
  • We validate If the value that user inserted is valid. If there is at least one “http” or “https” occurrence the value is OK, otherwise it’s in valid and we need to use the default value
  • Then we show the errors, if there’s any
  • Now we start the actual HTML, adding the default value in the input field as we’ve got in the PHP

After this point we need to actually save what’s being sent by the user. We’ll use the “save_post” hook, so every time WordPress saves a post it’ll call this function:

//saves custom field data
function save_custom_url( $post_id ) {
    global $post;    

    if( isset($_POST['siteurl']) ) {
        update_post_meta( $post->ID, 'urllink', $_POST['siteurl'] );
    }
}
add_action( 'save_post', 'save_custom_url' );

Here we just check if there’s any post data called “sitelink” which is our field name. If there is a sitelink, let’s save it.

Loading our Custom Data

Now we need to actually load our items, and we’ll use the get_posts() function, mostly because we have only simple data so we don’t need a proper WP loop (that would add a lot of DB calls and we really don’t need it).

So, first let’s create a function to get our site’s link, if there’s any.

//return URL for a post
function get_url($post) {
    $urllink = get_post_meta( $post->ID, 'urllink', true );

    return $urllink;
}

Now, we can start the shortcode function.  A simple way to default and validate the shortcode data is creating the attributes for the loop as an array, so we can add new items as we need them, like this:

//registering the shortcode to show testimonials
function load_testimonials($a){

    $args = array(
        "post_type" => "testimonials"
    );

    if( isset( $a['rand'] ) && $a['rand'] == true ) {
        $args['orderby'] = 'rand';
    }
    if( isset( $a['max'] ) ) {
        $args['posts_per_page'] = (int) $a['max'];
    }
    //getting all testimonials
    $posts = get_posts($args);

    //HTML OUTPUT
}
add_shortcode("testimonials","load_testimonials");

As you can see we have the shortcode attributes loaded and passed to the $args array when they validate, in the format that WordPress needs it, so we can load posts using them.

Now we need to add some HTML code there, following flexslider’s default structure. Here is how it’ll look like:

echo '<div>';
    echo '<ul>';

    foreach($posts as $post){
        //getting thumb image
        $url_thumb = wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID));
        $link = get_url($post);
        echo '<li>';
            if ( ! empty( $url_thumb ) ) { echo '<img src="'.$url_thumb.'" />'; }
            echo '<h2>'.$post->post_title.'</h2>';
            if ( ! empty( $post->post_content ) ) { echo '<p>'.$post->post_content.'<br />'; }
            if ( ! empty( $link ) ) { echo '<a href="'.$link.'">Visit Site</a></p>'; }
        echo '</li>';
    }

    echo '</ul>';
echo '</div>';

Wait, but why would we create the HTML code inside of the PHP function? That’s because we can conditionally load content only if the user have added content, so you won’t have empty HTML tags, just waiting to mess up your layout.

What about the sidebar?

Most people just want to show testimonials in the sidebar, and this plugin won’t work really well since text widgets don’t process shortcodes. There’s a simple solution for this, just add this in your code:

add_filter('widget_text', 'do_shortcode');

 

The post How to Create a Testimonials Plugin appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/how-to-create-a-testimonials-plugin/feed/ 0
HTML to WordPress https://anjwebtech.com/html-to-wordpress/ https://anjwebtech.com/html-to-wordpress/#respond Fri, 31 Jul 2020 05:28:18 +0000 https://anjwebtech.com/?p=4118 When I first decided to convert a static HTML design to WordPress I did some searching for a tutorial to help me get started with the basics. Surprisingly, I didn’t find anything that was very complete or easy to follow. So, I decided to write a very basic tutorial on […]

The post HTML to WordPress appeared first on ANJ WebTech.

]]>
Custom WordPress Theme Guide

When I first decided to convert a static HTML design to WordPress I did some searching for a tutorial to help me get started with the basics. Surprisingly, I didn’t find anything that was very complete or easy to follow. So, I decided to write a very basic tutorial on how to convert a static HTML template into a WordPress theme. If you are an absolute beginner at developing WordPress themes then this should help you get started.

How WordPress Works

WordPress works in a rather straightforward manner but it may seem confusing if you are completely new to the concept. WordPress relies on PHP to call on different parts of your content from the database management system it stands on. For example, look in your /wp-content/themes/twentythirteen/ directory and open the header.php file. As you scroll through the code notice the PHP calls, they start with a <?php and end with a ?>.

<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>

 

This line uses PHP to look-up your blog’s name from the database and display it. This basic function of retrieving or calling some kind of data from your database and using PHP to display it in your HTML is how WordPress works. Throughout this process you will be substituting PHP for different parts of your content and your code. This will make editing easier in the long run, as you will find out. Now that you understand the basics of how WordPress works, lets get started.

First Things First

The first step is to create a new folder and name it whatever you want your theme to be called. Next, create two new files, style.css and index.php and place them in the folder. Believe it or not, these are the only two files you actually need for a WordPress theme. Now copy and paste the code from your original CSS file into the style.css file you just created. At the top add the following code:

/*
Theme Name: Replace with your Theme's name.
Theme URI: Your Theme's URI
Description: A brief description.
Version: 1.0
Author: You
Author URI: Your website address.
*/

These comments simply help WordPress properly identify the theme. Your stylesheet is now ready to go.

Chop It Up

Now let’s start chopping up your HTML. Remember how we talked about WordPress using PHP to call data from your database? WordPress can also use PHP to call different files from within your template folder. Imagine your current HTML code chopped up into 4 (or more) different sections. For example, take a look at the layout and corresponding HTML of this page. The header comes first, followed by the content, and finally the footer. Instead of keeping these 3 parts of the HTML together in one file, you are going to put each of them in their own separate file. Then call on them one by one using PHP.

Now create 3 new files (header.phpsidebar.phpfooter.php) and place them in your theme directory. Next take a look at the header.php file from the Twenty Thirteen theme we looked at earlier. Notice all the PHP that is used in between the <head> tags. Copy that code to your new header.php file. Now open up your original HTML file and copy the code you marked off for your header (1st section) into your new header.php file (underneath the <head> section). Save and close.

Now open up your new index.php file. Copy the second part of your original HTML code, the content (2nd section) into your new index.php file. Save and close.

Getting the hang of it?

Next open up your new sidebar.php file, copy the sidebar (3rd section) of your original code into the sidebar.php file. Finally, copy the original footer (4th section) of code into your new footer.php file.

Put It Back Together

Your original code should now be chopped up into 4 different files (header.php, index.php, sidebar.php, footer.php). Let’s put it back together using a few lines of PHP. Open up your index.php file, it should contain the HTML from the content (2nd section) of your original code. Add this line at the very top of the file:

<?php get_header(); ?>

Now go to the absolute bottom of your index.php file and add these two lines:

<?php get_sidebar(); ?>
<?php get_footer(); ?>

These 3 simple lines of PHP are telling WordPress to fetch and display your header.phpsidebar.php, and footer.php files within your index.php file. Your code is now officially put back together. Now, if you want to edit your sidebar you can just edit your sidebar.php file, instead of sorting through your index.php to find it. The same goes for your header.php and your footer.php.

The Loop

Your index.php is almost finished. The final step is to insert the actual content into the code. Luckily, WordPress uses PHP for this as well. The Loop is the PHP function WordPress uses to call and display your posts from the database they are saved in. Grab this code and paste it into your new theme’s index.php file (inside of whichever div you are using to hold your content).

<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
  <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <div class="post-header">
        <div class="date"><?php the_time( 'M j y' ); ?></div>
        <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <div class="author"><?php the_author(); ?></div>
    </div><!--end post header-->
    <div class="entry clear">
        <?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
        <?php the_content(); ?>
        <?php edit_post_link(); ?>
        <?php wp_link_pages(); ?>
    </div><!--end entry-->
    <div class="post-footer">
        <div class="comments"><?php comments_popup_link( 'Leave a Comment', '1 Comment', '% Comments' ); ?></div>
    </div><!--end post footer-->
  </div><!--end post-->
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
  <div class="navigation index">
    <div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
    <div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
  </div><!--end navigation-->
<?php else : ?>
<?php endif; ?>

You just inserted a basic version of the loop into your code! WordPress will use the loop to display your posts and comments on your website.

The End

Now upload your theme folder to /wp-content/themes/. Then log into WordPress and activate your theme. Wasn’t that easy?

The post HTML to WordPress appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/html-to-wordpress/feed/ 0
How to make a Laravel app multi-tenant in minutes https://anjwebtech.com/how-to-make-a-laravel-app-multi-tenant-in-minutes/ https://anjwebtech.com/how-to-make-a-laravel-app-multi-tenant-in-minutes/#respond Tue, 28 Jul 2020 12:06:42 +0000 https://anjwebtech.com/?p=3831 It’s a multi-tenancy package that lets you turn any Laravel application multi-tenant without having to rewrite the code. It’s as plug-and-play as tenancy packages get.  Side note: In this tutorial, we’ll go over the most common setup — multi-database tenancy on multiple domains. If you need a different setup, it’s 100% […]

The post How to make a Laravel app multi-tenant in minutes appeared first on ANJ WebTech.

]]>

It’s a multi-tenancy package that lets you turn any Laravel application multi-tenant without having to rewrite the code. It’s as plug-and-play as tenancy packages get.

 Side note: In this tutorial, we’ll go over the most common setup — multi-database tenancy on multiple domains. If you need a different setup, it’s 100% possible. Just see the package’s docs. 

How it works

This package is unique in the sense that it doesn’t force you to write your application in a specific way. You can write your app just like you’re used to, and it will make it multi-tenant automatically, in the background. You can even integrate the package into an existing application.

Here’s how it works:

  1. A request comes in
  2. The package recognizes the tenant from the request (using domain, subdomain, path, header, query string, etc)
  3. The package switches the default database connection to the tenant’s connection
  4. Any database calls, cache calls, queued jobs, etc will automatically be scoped to the current tenant.

Installation

First, we require the package using composer:

composer require stancl/tenancy

Then, we run the tenancy:install command:

php artisan tenancy:install

This will create a few files: migrations, config file, route file and a service provider.

Let’s run the migrations:

php artisan migrate

Register the service provider in config/app.php. Make sure it’s on the same position as in the code snippet below:

/*
 * Application Service Providers...
 */
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\TenancyServiceProvider::class, // <-- here

Now we create a custom tenant model. The package is un-opinionated, so to use separate databases and domains, we need to create a slightly customized tenant model. Create a app/Tenant.php file with this code:

<?php

namespace App;

use Stancl\Tenancy\Database\Models\Tenant as BaseTenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Database\Concerns\HasDatabase;
use Stancl\Tenancy\Database\Concerns\HasDomains;

class Tenant extends BaseTenant implements TenantWithDatabase
{
    use HasDatabase, HasDomains;
}

And now we tell the package to use that model for tenants:

// config/tenancy.php file

'tenant_model' => \App\Tenant::class,

The two parts

The package sees your app as two separate parts:

  • the central app — which hosts the landing page, maybe a central dashboard to manage tenants etc
  • the tenant app — which is the part that your users (tenants) use. This is likely where most of the business logic will live

Separating the apps

Now that we understand the two parts, let’s separate our application accordingly.

Central app

First, let’s make sure the central app is only accessible on central domains.

Go to app/Providers/RouteServiceProvider.php and make sure your web and api routes are only loaded on the central domains:

protected function mapWebRoutes()
{
    foreach ($this->centralDomains() as $domain) {
        Route::middleware('web')
            ->domain($domain)
            ->namespace($this->namespace)
            ->group(base_path('routes/web.php'));
    }
}

protected function mapApiRoutes()
{
    foreach ($this->centralDomains() as $domain) {
        Route::prefix('api')
            ->domain($domain)
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));
    }
}

protected function centralDomains(): array
{
    return config('tenancy.central_domains');
}

Now go to your config/tenancy.php file and actually add the central domains.

I’m using Valet, so for me the central domain is saas.test and tenant domains are for example foo.saas.test and bar.saas.test.

So let’s set the central_domains key:

'central_domains' => [
    'saas.test', // Add the ones that you use. I use this one with Laravel Valet.
],

Tenant app

Now, the fun part. This part is almost too simple.

To make some code tenant-aware, all you need to do is:

  • move the migrations to the tenant/ directory
  • move the routes to the tenant.php route file

That’s it.

Having migrations in that specific folder tells the package to run those migrations when a tenant is created. And having routes in that specific route file tells the package to identify tenants on that route.

If you have an existing app, do this with your code. If you’re using a fresh app, follow this example:

Your tenant routes will look like this by default:

Route::middleware([
    'web',
    InitializeTenancyByDomain::class,
    PreventAccessFromCentralDomains::class,
])->group(function () {
    Route::get('/', function () {
        return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
    });
});

These routes will only be accessible on tenant (non-central) domains — the PreventAccessFromCentralDomains middleware enforces that.

Let’s make a small change to dump all the users in the database, so that we can actually see multi-tenancy working. Add this to the middleware group:

Route::get('/', function () {
    dd(\App\User::all());
    return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
});

And now, the migrations. Simply move migrations related to the tenant app to the database/migrations/tenant directory.

So, for our example: To have users in tenant databases, let’s move the users table migration to database/migrations/tenant. This will prevent the table from being created in the central database, and it will be instead created in the tenant database when a tenant is created.

Trying it out

And now let’s create some tenants.

We don’t yet have a landing page where tenants can sign up, but we can create them in tinker!

So let’s open php artisan tinker and create some tenants. Tenants are really just models, so you create them like any other Eloquent models.

Note that we’re using domain identification here. So make sure the domains you use will point to your app. I’m using Valet, so I’m using *.saas.test for tenants. If you use php artisan serve, you can use foo.localhost, for example.

    >> $tenant1 = Tenant::create(['id' => 'foo']);
    >> $tenant1->domains()->create(['domain' => 'foo.saas.test']);
>>>
    >> $tenant2 = Tenant::create(['id' => 'bar']);
    >> $tenant2->domains()->create(['domain' => 'bar.saas.test']);

And now we’ll create a user inside of each tenant’s database:

App\Tenant::all()->runForEach(function () {
    factory(App\User::class)->create();
});

And that’s it — we have a multi-tenant app!

If you visit foo.saas.test (or your environment’s equivalent), you will see a dump of users.

If you visit bar.saas.test, you will see a dump of different users. The databases are 100% separated, and the code we use — App\User::all() — does not need to know about tenancy at all! It all happens automatically in the background. You just write your app like you’re used to, without having to think of any scoping yourself, and it all just works.

The post How to make a Laravel app multi-tenant in minutes appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/how-to-make-a-laravel-app-multi-tenant-in-minutes/feed/ 0
Methods to find a smart and strategic web design company https://anjwebtech.com/methods-to-find-a-smart-and-strategic-web-design-company/ https://anjwebtech.com/methods-to-find-a-smart-and-strategic-web-design-company/#respond Tue, 21 Jul 2020 07:56:56 +0000 https://anjwebtech.com/?p=248 A strategically and smartly designed website draws clients immediately, gets more clicks and close sales in an enhanced form, increasing your profits in an unexpected manner. Professional web design companies get used to a work culture and create an exceptional practice that makes sure the innovation in your web design […]

The post Methods to find a smart and strategic web design company appeared first on ANJ WebTech.

]]>

A strategically and smartly designed website draws clients immediately, gets more clicks and close sales in an enhanced form, increasing your profits in an unexpected manner. Professional web design companies get used to a work culture and create an exceptional practice that makes sure the innovation in your web design layout design with the advanced technology and maintenance service to developed an effective website which generates excellent sales results. Before selecting a company for web design solutions, read on the following methods for truncating your selection time and difficulties.

1. Smart web design companies communicate in-person, through mail or over phone
Experienced web design companies tend to communicate appropriately with their clients using diverse modes. These include email, live chat and phone. According to your individual requirements, you can choose the communication preference that fits you the most.

2. Website designing budgets are set around Results
The qualified employees of a web design company prefer to place your budget around your expected results. It mainly connects the idea of flat fees offer with hour-wise billing for main application design and installation procedure rather than forcing you into an open-ended billing procedure.

3. Smart web design companies have flexible billing options
You are likely to be charged 20-25% of the project cost in advance and the remaining amount can be paid through online payments and cheques.

4. A web designing company shares its creative work
With flawlessly maintained portfolios comprising some of its best work samples, web design companies ensure to share its creative work sample with its customers on demand. You can go through them to know the competence of the web design company and the impact of its previous web designed solutions.

5. Strategic web design companies use both stock and scratch images
The qualified website designing companies always use a set of template stock images to accelerate your work. While designing a site for your specific business, they select the related template and personalize it from scratch to cater your designing requirements and bring into freshness and exceptionality in your design.

6. Strategic website designing companies let you handle small updates
Smart and strategic web designing team creates models for websites, comprising digital publishing interfaces that update and ease the procedure for making small and frequent changes. These models function so perfectly that you will be competent to make frequent updates with your in-house designers who are newbies.

7. The smartest web designing company sticks to the latest web standards and browser accessibility
Apart from using a smart source of designing techniques, a web design company basically sticks to the latest web standards for interface design and browser compatibility. It can even ensure SEO-friendly designing to put off your site from getting lost in web world search.

The post Methods to find a smart and strategic web design company appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/methods-to-find-a-smart-and-strategic-web-design-company/feed/ 0
Redesign your website without losing your business sales https://anjwebtech.com/redesign-your-website-without-losing-your-business-sales/ https://anjwebtech.com/redesign-your-website-without-losing-your-business-sales/#respond Mon, 20 Jul 2020 07:57:03 +0000 https://anjwebtech.com/?p=247 Change can be hard for people. We’re creatures of habit after all; we like what we like and we stick to it. This simple fact can make redesigning your website a daunting task. The last thing you want to do is redesign your website, only for it to be completely […]

The post Redesign your website without losing your business sales appeared first on ANJ WebTech.

]]>

Change can be hard for people. We’re creatures of habit after all; we like what we like and we stick to it. This simple fact can make redesigning your website a daunting task. The last thing you want to do is redesign your website, only for it to be completely unrecognizable and undesirable to your customers.

Your customers have built trust with you over a period of time. If you redesign your website without your customers in mind, you risk losing that trusting relationship you’ve worked so hard to build. While your long-time, most loyal customers might be more inclined to stick around, what about casual visitors or the first-time visitors of your newly overhauled site? Statistics show that once your page loads, users form an opinion in .05 seconds. First impressions are incredibly important and you want your website redesign to impress customers and prospects, not scare them away.

Here’s how to redesign your website without losing customers.

Set goals.

While having a beautiful looking website is important, don’t dive headfirst into a redesign of your website purely for personal aesthetic purposes; you want to go into your website redesign with clear goals in mind. Setting goals for your website redesign will not only make the redesign go smoothly but it will also allow you to tell your customers exactly why there’s changes being made. So, they’ll be less likely to be concerned about the website redesign and more likely to be excited about what’s coming next.

Some goals you might want to achieve for your website redesign could be:

  • Making your site easier to navigate and make finding content simpler, which increases your pages per visit.
  • Boost your site speed, which can lower your bounce rate.
  • Add more pages and content to increase time spent on pages.
  • Improve your on-site SEO to increase organic traffic.
  • Make your site mobile-friendly to capture more audiences.
  • Boost social shares by making your site more visually appealing.

Aside from setting goals for what you want your site redesign to accomplish, you should also set a deadline for your redesign. Setting a goal date for completion will help your team stay on track and deliver a new and improved website in a timely fashion.

Let customers know you’re redesigning.

As briefly mentioned before, you want your customers to be excited about the website redesign, so don’t leave them in the dark. Email marketing is still one of the best ways to get in touch with your customers. In fact, according to HubSpot, more than 50% of U.S respondents check their personal email account more than 10 times a day. So, you should be sending out emails to all of your subscribers letting them know that a website redesign is in the works, as well as an email to welcome them to the new and improved site once it’s live, like in the example from Lonely Planet below.

Instead of customers stumbling onto your site and being confused by the unfamiliar appearance, they’ll be notified and ready for the change. Your website redesign can also become new content for your blog. You can keep customers up-to-date with the process, let them know about the exciting new features, and share tips based on your experience.

Get feedback.

While you’re letting your customers know that your website is getting a redesign, take the opportunity to ask them for feedback. Your customers thoughts and opinions are important; after all, they’re the ones who’re using your website. So, consider creating an online form that allows your customers to share their ideas on how you can improve your website design.

To get actionable insights on what your customers want to see with your website redesign, ask them questions such as:

  • What is your favorite feature on our website?
  • What is your least favorite feature?
  • How easy is it to find what you’re looking for?
  • What’s missing on our website that you’d like to see?
  • How can we create a website that better serves your needs?

Your customers will be thrilled that you included them in the makeover process and they’ll be over the moon when they see that their suggestions have been implemented in the new design of your site.

Do quality assurance testing.

After you’ve redesigned your website, you probably can’t wait to release it to the world — but wait. Before you unveil your website redesign you need to do quality assurance testing. The last thing you want to do is launch your new website when it’s not ready and doesn’t work properly. This can be an inconvenience to your customers and create all sorts of problems for you.

Have your team test out every aspect of your new website before you release it. They should be testing from the customer perspective; making sure the site works on multiple different browsers, that it’s optimized for mobile, and overall functionality. They should also be checking for bugs from an administrative and SEO perspective as well. Catching any bugs on your website beforehand is vital to a successful launch.

Over to you.

Redesigning your website can be stressful but it can also put you on a path for increased traffic and a boost in conversions, as long as it’s done right. Don’t forget to do A/B testing of your new site. Not every website redesign is perfect right away, but with A/B testing you can find out exactly what works best for your customers. Enjoy your site’s new design and all the perks that come along with it.

The post Redesign your website without losing your business sales appeared first on ANJ WebTech.

]]>
https://anjwebtech.com/redesign-your-website-without-losing-your-business-sales/feed/ 0