How to get my domain or server url with php?

<?php
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$website = $protocol . '://' . $host;
?>

<a href="<?php echo $website; ?>">my site</a>

How to use $_SERVER['SERVER_NAME'] with a href ?

<?php
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$website = $protocol . '://' . $host;
?>

<a href="<?php echo $website; ?>">my site</a>

PHP $_SERVER['SERVER_NAME'] correct use

<?php
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$website = $protocol . '://' . $host;
?>

<a href="<?php echo $website; ?>">my site</a>

How to get categories in wordpress?

Dropdown Box

Here's how to create a dropdown box of the subcategories of, say, a category that archives information on past events. This mirrors the example of the dropdown example of wp_get_archives which shows how to create a dropdown box for monthly archives.
Suppose the category whose subcategories you want to show is category 10, and that its category "nicename" is "archives".
<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
 <option value=""><?php echo esc_attr(__('Select Event')); ?></option> 
 <?php 
  $categories = get_categories('child_of=10'); 
  foreach ($categories as $category) {
   $option = '<option value="/category/archives/'.$category->category_nicename.'">';
 $option .= $category->cat_name;
 $option .= ' ('.$category->category_count.')';
 $option .= '</option>';
 echo $option;
  }
 ?>
</select>

List Categories and Descriptions

This example will list in alphabetic order, all categories presented as links to the corresponding category archive. Each category descripition is listed after the category link.
<?php
$args = array(
  'orderby' => 'name',
  'order' => 'ASC'
  );
$categories = get_categories($args);
  foreach($categories as $category) { 
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Description:'. $category->description . '</p>';
    echo '<p> Post Count: '. $category->count . '</p>';  } 
?>

Get only top level categories

To get the top level categories only, set parent value to zero. This example gets link and name of top level categories.
<?php
$args = array(
  'orderby' => 'name',
  'parent' => 0
  );
$categories = get_categories( $args );
foreach ( $categories as $category ) {
 echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a><br/>';
}
?>
Source: https://codex.wordpress.org/Function_Reference/get_the_category_list

Remove Default round border of select element in Mac OS Browser, Chrome and android

select{ 
   -webkit-appearance: none;
   -moz-appearance:    none;
   appearance:         none;   
   -webkit-border-radius: 0;  /* Safari 3-4, iOS 1-3.2, Android 1.6- */    
   -moz-border-radius: 0;  /* Firefox 1-3.6 */     
   border-radius: 0;  /* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android 2.1+ */
}

How to get element by class?

<div class="color">
  <p>P element in first div with color. Div's index is 0.</p>
</div>


<script>
var x = document.getElementsByClassName("color");
alert(x[0].innerHTML);
</script>

Simple Pagination With PHP & MYSQL

Data Pagination is one of the comman task we have in web applications. When we get huge data form database insted of show all of it at once we will choose different ways to display that data. One such technique is php pagination.
In this tutorial we will use php and mysql to create simple pagination script.Pagination  lets you to paging your data in to number of pages. I simplifed code as much as possible. In the below example I have taken Country database with its country code. Please check on below link to check the demo. The countries database is included in countries.sql in the download file.
Simple Pagination With PHP & MYSQL
We will create these pages. -config.php (Database Configuration) -index.php -paginate.php Let's First create database table which we are going to use in our example. 

DataBase

  1. CREATE TABLE IF NOT EXISTS `countries` (
  2. `ccode` varchar(2) NOT NULL DEFAULT '',
  3. `country` varchar(200) NOT NULL DEFAULT '',
  4. PRIMARY KEY (`ccode`)
  5. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The above is simple countries table. Just execute the above command in your MySQL command prompt orphpmyadmin area.

config.php


  1. $mysql_hostname = "host";
  2. $mysql_user = "usr";
  3. $mysql_password = "pass";
  4. $mysql_database = "db";
  5.  
  6. $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
  7. mysql_select_db($mysql_database, $bd) or die("Error on database connection");
This is the configuration file. Here you need to setup your database details. 

index.php

  1. <?php
  2. include('config.php'); //include of db config file
  3. include ('paginate.php'); //include of paginat page
  4. $per_page = 5; // number of results to show per page
  5. $result = mysql_query("SELECT * FROM countries");
  6. $total_results = mysql_num_rows($result);
  7. $total_pages = ceil($total_results / $per_page);//total pages we going to have
  8. //-------------if page is setcheck------------------//
  9. if (isset($_GET['page'])) {
  10. $show_page = $_GET['page']; //current page
  11. if ($show_page > 0 && $show_page <= $total_pages) {
  12. $start = ($show_page - 1) * $per_page;
  13. $end = $start + $per_page;
  14. } else {
  15. // error - show first set of results
  16. $start = 0;
  17. $end = $per_page;
  18. }
  19. } else {
  20. // if page isn't set, show first set of results
  21. $start = 0;
  22. $end = $per_page;
  23. }
  24. // display pagination
  25. $page = intval($_GET['page']);
  26. $tpages=$total_pages;
  27. if ($page <= 0)
  28. $page = 1;
  29.  
  30. ?>
Here we included two files config.php and paginate.php in first two lines. we can set $per_page to how many records you want to show on a page. We can calculate total pages depending on total results and per_page. Depending on the $_GET['page'] we can have start and end records. 

index.php(Displaying Data)

  1. <?php
  2. $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
  3. echo '<div class="pagination"><ul>';
  4. if ($total_pages > 1) {
  5. echo paginate($reload, $show_page, $total_pages);
  6. }
  7. echo "</ul></div>";
  8. // display data in table
  9. echo "<table class='table table-bordered'>";
  10. echo "<thead><tr><th>country code</th> <th>Country Name</th></tr></thead>";
  11. // loop through results of database query, displaying them in the table
  12. for ($i = $start; $i < $end; $i++) {
  13. // make sure that PHP doesn't try to show results that don't exist
  14. if ($i == $total_results) {
  15. break;
  16. }
  17. // echo out the contents of each row into a table
  18. echo "<tr " . $cls . ">";
  19. echo '<td>' . mysql_result($result, $i, 'ccode') . '</td>';
  20. echo '<td>' . mysql_result($result, $i, 'country') . '</td>';
  21. echo "</tr>";
  22. }
  23. // close table>
  24. echo "</table>";
  25. // pagination
  26. ?>
This part will loop from $start to $end variable. The records will be displayed on the page. 

paginate.php

  1. function paginate($reload, $page, $tpages) {
  2. $adjacents = 2;
  3. $prevlabel = "&lsaquo; Prev";
  4. $nextlabel = "Next &rsaquo;";
  5. $out = "";
  6. // previous
  7. if ($page == 1) {
  8. $out.= "<span>".$prevlabel."</span>\n";
  9. } elseif ($page == 2) {
  10. $out.="<li><a href=\"".$reload."\">".$prevlabel."</a>\n</li>";
  11. } else {
  12. $out.="<li><a href=\"".$reload."&amp;page=".($page - 1)."\">".$prevlabel."</a>\n</li>";
  13. }
  14. $pmin=($page>$adjacents)?($page - $adjacents):1;
  15. $pmax=($page<($tpages - $adjacents))?($page + $adjacents):$tpages;
  16. for ($i = $pmin; $i <= $pmax; $i++) {
  17. if ($i == $page) {
  18. $out.= "<li class=\"active\"><a href=''>".$i."</a></li>\n";
  19. } elseif ($i == 1) {
  20. $out.= "<li><a href=\"".$reload."\">".$i."</a>\n</li>";
  21. } else {
  22. $out.= "<li><a href=\"".$reload. "&amp;page=".$i."\">".$i. "</a>\n</li>";
  23. }
  24. }
  25. if ($page<($tpages - $adjacents)) {
  26. $out.= "<a style='font-size:11px' href=\"" . $reload."&amp;page=".$tpages."\">" .$tpages."</a>\n";
  27. }
  28. // next
  29. if ($page < $tpages) {
  30. $out.= "<li><a href=\"".$reload."&amp;page=".($page + 1)."\">".$nextlabel."</a>\n</li>";
  31. } else {
  32. $out.= "<span style='font-size:11px'>".$nextlabel."</span>\n";
  33. }
  34. $out.= "";
  35. return $out;
  36. }
This is our main code which created the pagination html code and this code will be called from our index.php. In this first we need to set the $adjacents which is for how many li u want to display beside your current selected page. The remaining code will generate the li of the links.

Source: 
http://www.techumber.com/2012/08/simple-pagination-with-php-mysql.html