Author: therichpost

  • Full Calendar Integration in Angular Latest Versions

    Full Calendar Integration in Angular Latest Versions

    Hello to all, welcome to therichpost.com. In this post, I came with easy solution for Full Calendar Integration in Angular Latest Versions.

    If you are new in Angular 7 then you can check my old posts related to Angular 7.

    In this post, I will make Full Calendar Integration in Angular Latest Version(Angular 7.2.6) seems very easy with the help of jQuery(My Love).



    Here are the complete code snippet you need to follow carefully:

    1. Here are some basics commands to add new Angular setup and other libraries:

    npm install -g @angular/cli
    
    ng new easyfullcalendar
    
    cd easyfullcalenar
    
    npm install jquery --save
    
    npm i fullcalendar
    
    npm i moment

     

    2. Here is code, you need to add your angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/fullcalendar/dist/fullcalendar.min.css"
                ],
                "scripts": ["node_modules/jquery/dist/jquery.min.js",
                "node_modules/moment/min/moment.min.js",
                "node_modules/fullcalendar/dist/fullcalendar.min.js"]
    ...

    3. Here is the code, you need to add app.component.ts file:

    import { Component } from '@angular/core';
    declare var $: any;
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'easyfullcalendar';
    
    ngOnInit(){
           setTimeout(() => {
            $("#calendar").fullCalendar({  
                            header: {
                                left   : 'prev,next today',
                                center : 'title',
                                right  : 'month,agendaWeek,agendaDay'
                            },
                            navLinks   : true,
                            editable   : true,
                            eventLimit : true,
                            events: [
                                {
                                    title : 'This is your',
                                    start : '2019-03-03T12:30:00',
                                    color : '#f9c66a' // override!
                                },
                                {
                                    title : 'Your meeting with john',
                                    start : '2019-03-07T12:30:00',
                                    end   : '2019-03-09',
                                    color : "#019efb"
                                },
                                {
                                    title  : 'This is Today',
                                    start  : '2019-03-12T12:30:00',
                                    allDay : false, // will make the time show,
                                    color  : "#57cd5f"
                                }
                            ],  // request to load current events
                        });
    
         }, 100);
       }
    }

    4. Here is the code, you need to add app.component.html file:

    <div id="calendar"></div>

     

    This is it and you have any query or you need to ask something then please comment below.

    Harjas,

    Thank you.

    Note: if you will get below error:

    “node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ‘;’ expected”

    The do below steps:

    Step 1 : Go to package.json and modify “rxjs”: “^6.0.0” to “rxjs”: “6.0.0” Step 2 Run npm update in your project.Step 1 : Go to package.json and modify “rxjs”: “^6.0.0” to “rxjs”: “6.0.0”

    Step 2 Run npm update in your project.

  • Angular 7 Drag Drop Working Example

    Angular 7 Drag Drop Working Example

    Hello to all, welcome to therichpost.com, Today I am going to tell you Angular 7 Drag Drop Working Example

    if you are new in Angular 7 then you can check my old posts related to Angular 7.

    In Angular 7, drag drop and I have used, jQuery and Jquery-ui.


    Angular 7 Drag Drop Working Example

    Angular 7 Drag Drop Working Example2

    Here is the working code snippet for Angular 7 Drag Drop Working Example:


    1. Here is the basic npm commands to install Angular 7, jQuery, jQuery UI on your local system:

    ng new angulardragdrop // New Angular 7
    
    cd angulardragdrop // New Angular 7 Setup Folder
    
    $ npm install jquery --save // Install Jquery
    
    $ npm install jquery-ui-dist // Install Jquery UI

     


    2. Add below code into angular.json file:

    ...
    "styles": [
                  "src/styles.css",
                  "node_modules/jquery-ui-dist/jquery-ui.min.css"
                ],
                "scripts": ["node_modules/jquery/dist/jquery.js",
                  "node_modules/jquery-ui-dist/jquery-ui.min.js"]
    ...

     


    3. Add below code into app.component.ts file:

    import { Component } from '@angular/core';
    declare var $ :any;
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'angulardragdrop';
      ngOnInit() {
      	$( "#sortable1, #sortable2" ).sortable({
          connectWith: ".connectedSortable"
        }).disableSelection();
      }
    }

    4. Now add below code into app.component.html file:

    <ul id="sortable1" class="connectedSortable">
      <li class="ui-state-default">Item 1</li>
      <li class="ui-state-default">Item 2</li>
      <li class="ui-state-default">Item 3</li>
      <li class="ui-state-default">Item 4</li>
      <li class="ui-state-default">Item 5</li>
    </ul>
    
    <ul id="sortable2" class="connectedSortable">
      <li class="ui-state-highlight">Item 1</li>
      <li class="ui-state-highlight">Item 2</li>
      <li class="ui-state-highlight">Item 3</li>
      <li class="ui-state-highlight">Item 4</li>
      <li class="ui-state-highlight">Item 5</li>
    </ul>
     <style>
      #sortable1, #sortable2 {
        border: 1px solid #eee;
        width: 142px;
        min-height: 20px;
        list-style-type: none;
        margin: 0;
        padding: 5px 0 0 0;
        float: left;
        margin-right: 10px;
      }
      #sortable1 li, #sortable2 li {
        margin: 0 5px 5px 5px;
        padding: 5px;
        font-size: 1.2em;
        width: 120px;
      }
      </style>

    5. Run ng serve command into your terminal to see the output.

    This is it. If you have any query related to this post then please do comment below or ask question.

    Jassa Jatt

    Thank you.

  • How to get Woocommerce Product Attributes names and value?

    How to get Woocommerce Product Attributes names and value?

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to get woocommerce product attributes names and value?

    Woocommerce is know for the best e-commerce wordpress plugin and User can easily add and sell his/her products easily.

    Woocommerce has great ability to add extra features or I can extra attributes of any product and I will show the code to get that attributes.



    If you are new in Woocommerce then you can check my old posts related to Woocommerce.


    1. Here is the code for How to get Woocommerce Product Attributes names and value? and you can add this code anywhere into your wordpress theme’s template file and I am doing to this for single product but we can also use this code in wp query for product:

    <?php $product_attr = get_post_meta( get_the_ID(), '_product_attributes' ); ?>
    <table>
     <tbody>
          <?php 
              foreach ($product_attr as $attr) {
                  foreach ($attr as $attribute) { ?>
                    <tr>
                       <th><?php $attrnames = str_replace("pa_", "", $attribute['name']);
                                  echo str_replace("-", " ", $attrnames);
                         ?></th>
                        <td><?php $attrvalue = array( wc_get_product_terms( get_the_ID(), $attribute['name'], array( 'fields' => 'names' ) ) );
                            $attrvalues = implode(",", $attrvalue[0]);
                            echo $attrvalues;
                         ?></td>
                    </tr>
          <?php } } ?>
     </tbody>
    </table>

     

    If you have any query related to this post, then please let me know.

    Jassa Jatt,

    Thank you

  • Angular 7 Pagination Working Example

    Angular 7 Pagination Working Example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 7 Pagination Working Example.

    If you are new in Angular 7, then please check my old posts related to Angular 7.

    In this post, I am making custom pagination with bootstrap styling in Angular 7.


    Angular 7 Pagination Working Example

    Here is the complete code for Angular 7 Pagination Working Example


    1. Here is the code for app.component.html file and I have used bootstrap for better styling:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
      <style type="text/css">
        .col-sm-6 {
        -ms-flex: 0 0 50%;
        flex: 0 0 50%;
        max-width: 49%;
        background: #eee;
        float: left;
        margin: 5px;
        display: none;
    }
      </style>
    </head>
    <body>
    
    <div class="jumbotron text-center">
      <h1>Angular 7 Custom pagination Working Example:-</h1> 
    </div>
      <div class="container">    
        <div class="row" id="mainDiv">
          <div class="col-sm-6">
            1.
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          </div>
          <div class="col-sm-6">
            2.
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.    
          </div>
          <div class="col-sm-6">
            3.
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          </div>
          <div class="col-sm-6">
            4.
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.    
          </div>
          <div class="col-sm-6">
            5.
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          </div>
          <div class="col-sm-6">
            6.
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.    
          </div>
          <div class="col-sm-6">
            7.
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          </div>
          <div class="col-sm-6">
            8.
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.    
          </div>
          <div class="col-sm-6">
            9.
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
          </div>
          <div class="col-sm-6">
            10.
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.    
          </div>
           <ul class="pagination pagination">
            <li class="page-item" *ngFor="let number of data">
              <a class="page-link" href="#" (click) = "textVal($event)">{{number}}</a>
            </li>
          </ul>
        </div>
      </div>
    </body>
    </html>

     

     

    1. Here is the code for app.component.ts file:

    import { Component } from '@angular/core';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title  = 'angularcustompaging';
      maxdiv = 4;
      divtotalCount : any;
      numofPages    : any;
      data = [];
      ngOnInit() {
        this.divtotalCount = document.getElementsByClassName("col-sm-6").length;
        this.numofPages = Math.ceil(this.divtotalCount/this.maxdiv);
      for(var i = 1; i <= this.numofPages; i++) {
          this.data.push(i);
      }
    
      var mainDiv = document.getElementById('mainDiv');
      for (var i = 0; i < this.maxdiv; i++) {
          mainDiv.children[i].setAttribute("style", "display:block");
      }
    
      for(var i = 0; i < this.divtotalCount; i++)
      {
    
        if(i<=4)
        {
          mainDiv.children[i].setAttribute("pagenum", "1");
        }
        if(i>=4 && i<=8)
        {
          mainDiv.children[i].setAttribute("pagenum", "2");
        }
        if(i>=8 && i<=12)
        {
          mainDiv.children[i].setAttribute("pagenum", "3");
        }
      
      }
      
      }
    
      textVal(event)
      {
          var pagesNum = event.target.innerText;
          
          var hideDiv  = document.querySelectorAll('div[pagenum]');
          hideDiv.forEach(function(item)
          {
            item.setAttribute("style", "display:none;");
          })
          hideDiv[0].setAttribute("style", "display:none");
          var showDiv  = document.querySelectorAll('[pagenum="'+pagesNum+'"]');
          showDiv.forEach(function(item)
          {
            item.setAttribute("style", "display:block");
          })
      }
      
    }

     


    This is just custom pagination with custom values and in next post, I will come custom pagination with dynamic values.

    If you have any query regarding to this post, then please let me know.

    Harjas,

    Thank you

  • Angular 7 Form Validation Methods for Different Input Fields

    Angular 7 Form Validation Methods for Different Input Fields

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 7 Form Validation Methods for Different Input Fields.

    If you are new in Angular 7, then please check old posts related to Angular 7.

    In this post, I will give you tell some form input fields validations tricks In Angular 7.

    ngOnInit() {
              this.formdata = new FormGroup({
                     //Number Validations and Min Max Validation
            	mobile_number : new FormControl("", [Validators.required, Validators.pattern("^[0-9]*$"), Validators.minLength(6), Validators.maxLength(10)]),
    
                     //Email Validation
            	email : new FormControl("", [Validators.required, Validators.email]),
    
                    //Min lenght Validation
            	password : new FormControl("",  [Validators.required, Validators.minLength(5)]),
    
                    //Empty Field Validation
            	package_type : new FormControl("", Validators.required),
    
           });
    
       
      }

     

    For more information, please comment below or ask questions.

    Harjas,

    Thank you

  • WordPress Custom Query get Posts based on Post Title

    WordPress Custom Query get Posts based on Post Title

    Hello to all, welcome to therichpost.com. In this post, I will tell you, WordPress Custom Query get Posts based on Post Title.

    I personally like WordPress very much and you can find many post related to WordPress Tricks, WordPress Hooks, WordPress.

    There are many ways to WordPress Posts but sometime we need to get WordPress Posts with custom mysql query and this is also good way.

    Today I am showing you custom mysql query to get WordPress Posts based on Post Title and Post Type.

    global $wpdb;
    $yourPostTitle=$_GET['s'];
    
    $query = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%$yourPostTitle%' AND post_type='product' AND post_status='publish'");
    foreach ($ids as $data) {
    $url = wp_get_attachment_url( get_post_thumbnail_id($data->ID), 'full' ); // Post Thumbnail
    ?>
    <a href="<?php echo get_permalink($data->ID); ?>"><img src="<?php echo $url ?>" /></a> // Post Link
    <h2><a href="<?php echo get_permalink($data->ID); ?>"><?php echo $data->post_title; ?></a></h2> // Post Title
    <?php }
    

     

    If you have any query related to this post, then please do comment below ask question.

    Jassa Jatt,

    Thank you

  • Get WordPress Post with Tag Id working example

    Get WordPress Post with Tag Id working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, How to Get WordPress Post with tag id working example.

    I personally like WordPress very much and you can find many post related to WordPress Tricks, WordPress Hooks, WordPress.

    Every day, I face new challenge in WordPress.

    Today I am going to share to simple but tricky code to get WordPress Post with Tag Id:

    1. Here is the working code and you can this into your WordPress theme’s template file:

    $query = new WP_Query( array(
    'post_type' => 'gd_place',
    'tax_query' => array(
    array (
    'taxonomy' => 'gd_place_tags',
    'field' => 'term_id', // term_id, slug or name or I can say tag id
    'terms' => 187,
    )
    ),
    ) );
    while ( $query ->have_posts() ) :
    $query ->the_post();
    the_title();
    endwhile;

     

     


    If you have any query related to this post, then please do comment below or ask questions.

    Jassa Jatt,

    Thank you

  • Angular 7 Ngx Editor Validation Working Example

    Angular 7 Ngx Editor Validation Working Example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 7 Ngx Editor Validation Working Example.

    If you are new in Angular and then please check my old post related to Angular 7 for basics information.

    I have already done the posts related to Angular Ngx Editor but, in this post, I will apply validation on Angular 7 Ngx Editor and here is the working code snippets. Please follow it carefully.


    Angular 7 Ngx Editor Validation Working Example

    1. Here are the basics query you need to run into your command prompt to install Angular 7 basic setup and Ngx Editore Package:

    npm install -g @angular/cli 
    
    ng new angularngxeditor //Create new Angular Project
    
    $ cd angularngxeditor // Go inside the Angular Project Folder
    
    npm install ngx-editor --save
    
    npm install --save font-awesome angular-font-awesome
    
    npm install ngx-bootstrap --save
    
    ng serve --open // Run and Open the Angular Project
    
    http://localhost:4200/ // Working Angular Project Url

     

    2. You need add below code into you app.module.ts file:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    
    import { AppComponent } from './app.component';
    import { NgxEditorModule } from 'ngx-editor';
    import { FormsModule, ReactiveFormsModule } from '@angular/forms';
    import { AngularFontAwesomeModule } from 'angular-font-awesome';
    import { HttpClientModule }    from '@angular/common/http';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        NgxEditorModule,
        FormsModule,
        HttpClientModule,
        AngularFontAwesomeModule,
        ReactiveFormsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

     

    3. Now you need to add below code into app.component.ts file:

    import { Component, OnInit } from '@angular/core';
    import { FormGroup, FormControl, Validators, ReactiveFormsModule} from '@angular/forms';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      title = 'ngxeditormaxlenght';
      formdata;
    
      ngOnInit() {
      		this.formdata = new FormGroup({
              	faq_question : new FormControl("", [Validators.required, this.noWhitespaceValidator,
              		Validators.maxLength(400), Validators.minLength(5)]),
           });
      }
    
      public noWhitespaceValidator(control: FormControl) {
          const isWhitespace = (control.value || '').trim().length === 0;
          const isValid = !isWhitespace;
          return isValid ? null : { 'whitespace': true };
      	}
    }
    

    4. Now you need to add below code into app.component.html file:

     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
     <div class="jumbotron text-center">
      <h1>Angular Ngx Editior Validation</h1>
      <p>Have fun!!</p> 
    </div>
     <div class="container">
     <form class="form" [formGroup] = "formdata" (ngSubmit)="on_submit(formdata.value)" novalidate method="post">
                      <div class="row">
    
                         <div class="col-md-12">
                            <div class="form-group" [ngClass]="{'error': formdata.controls.faq_question.errors && formdata.controls.faq_question.touched}">
                               <label for="NewQuestion">Type Anything</label>
                               <div class="input-group controls">
    
                                  <app-ngx-editor required formControlName = "faq_question" id="NewQuestion" placeholder="New Question" height="100px" minHeight="100px" [placeholder]="'Enter text here...'" [spellcheck]="true" [(ngModel)]="htmlContent"></app-ngx-editor>
    
                                  <div *ngIf="formdata.controls.faq_question.errors && formdata.controls.faq_question.touched" class="help-block clearfix mt-2">
                                    <ul role="alert">
                                      <li class="alert-danger p-2">This is required min5 max 400</li>
                                    </ul>
                                  </div>
                               </div>
                            </div>
                         </div>
    
                      </div>
                      <div class="row">
                         
                         <div class="col-md-12 m-b-12 m-t-12">
                            
                            <button type="submit" class="btn btn-success btn-lg waves-effect waves-light m-r-10" [disabled] = "!formdata.valid">Submit</button>
                            
    
                         </div>
                      </div>
                   </form>
                 </div>

     

    If you have any query related to this post, then please do comment below or ask questions.

    Harjas

    Thank you

  • WordPress Ajax working example

    WordPress Ajax working example

    Hello to all, welcome to therichpost.com. In this post, I will tell you, WordPress Ajax working example.

    If you are new in WordPress then please check old post related to WordPress.

    In this post, I am showing very simple WordPress Ajax working example but sometime this takes lot of time to find the solution.


    Here is I am showing the working code snippet and please follow carefully:


    1. Here is the code and you can add this code into any of your theme’s template file:

    <!-- Button Click for fire ajax request -->
    <button type="submit" class="btn btn-default" id="addProductUrl">Submit</button>
    
    
    <!-- Ajax Request Code -->
    <script>
      jQuery(document).ready(function($) {
        $("#addProductUrl").click(function(event) {
          event.preventDefault();
          /* Act on the event */
          var formData = new FormData();
          formData.append('action', 'foobar');
          formData.append('id', '12345');
          $.ajax({
              url: '<?php echo admin_url('admin-ajax.php'); ?>',
             type: 'post',
             contentType: false,
             processData: false,
             data: formData,
             success: function (response) {
                 //Get Ajax request response
                 console.log(response)
                 
             },
             error: function (response) {
              console.log(response)
             }
         });
        });
      });
    </script>

     

     

    2. Here is the working code and you need to add into theme’s functions.php file:

    add_action( 'wp_ajax_foobar', 'my_ajax_foobar_handler' );
    add_action('wp_ajax_nopriv_foobar', 'my_ajax_foobar_handler'); 
    function my_ajax_foobar_handler() {
        echo $_POST['id'];
    
       die();
    }

     

     

    This is it. If you have any query related to this post, then please do comment below or ask question.

    Harjas

    Thank you

  • How to add custom tab in Ultimate Member?

    How to add custom tab in Ultimate Member?

    Hello to all, In this post, I will show, How to add custom tab in Ultimate Member?


    How to add custom tab in Ultimate Member?

    I have tried so many hooks and functions but those did not work for me then I tried my own way and That trick worked for me.

    If you want to that code then contact me or comment below.

    Thank you.