Saturday 19 August 2017

Add manually limit number of post in WordPress

Here the code for Add  manually limit number of post in WordPress:

$args = array(
'post_type' => 'post',
'posts_per_page' => 12,
'paged' => $page,
);

query_posts($args);

Return MySQL data in JSON format

Here is the code for Return MySQL data in JSON format:

$con=mysqli_connect($servername,$username,$password,$databasename);
if (mysqli_connect_errno())
{
echo "Connection Error" . mysqli_connect_error();
}
$query = "SELECT * FROM TableName";
$result = mysqli_query($con,$query);
$querydata = array();
while($data = mysqli_fetch_array($result)) {
$querydata[] = $data;
}
echo json_encode($querydata);
mysqli_close($con);

Convert Codeigniter data to json

Here is the code for Convert Codeigniter data to json:

public function lastActivity()
{
    header("Content-Type: application/json");
    $this->db->select('*');
    $this->db->from('table_name');
    $query = $this->db->get();

    return json_encode($query->result());
}

Select all anchors with a specific href with jquery

Here is the code for Select all anchors with a specific href with jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
      $(document).ready(function(){
        $("a").each(function(){
    if($(this).attr("href") == "http://example.com/external/link/")
    {
        $(this).hide();
    }
});
});
 </script>
  <a href="http://example.com/external/link/">a website link</a>

Add three dots at end of line with css

Add three dots at end of line with css here is the code:

.add-three-dots{display: inline-block;

   width: 240px;
   white-space: nowrap;
   overflow: hidden;
   text-overflow: ellipsis;
   background: #FFFCD7;
    padding: 5px;
     }
 <span class="add-three-dots">How To Add Three Dots In the End Of String with Css And Jquery?</span>

Make MySQL database connection with oops

Here is the code for Make MySQL database connection with oops:

class config
{
var $servername;
var $username;
var $password;
var $database;
function database($servername, $username, $password, $database)
{

$conn=new mysqli($this->servername,$this->username,$this->password,$this->database);
if($conn->connect_error){
die("connection failed".$conn->connect_error);

}

}
}
$connect_database = new config();
$connect_database->database("localhost", "root", "", "oops");

Insert query in php mysql with form post data

Here is the code for Insert query in php mysql with form post data:

$name    = $_POST["cname"];
$phone   = $_POST["cphone"];
$email   = $_POST["cemail"];

$con = mysqli_connect("localhost", "root", "", "oops");

$sql = "INSERT INTO `user`(`name`, `phone`, `email`) VALUES ('$name', '$phone', '$email')";

$result = mysqli_query($con, $sql);

if($result) {
    echo "user added";
} else {
    echo "user did not add";
}

Remove Wrong Words From your website In php

Here is the code for Remove Wrong Words From your website in php:

$string = "badworde you a badwords, hello badwordd..";
$a1=array("badworde","badwords", "badwordd");
$a2=array("beep","beep", "beep");
$result = str_replace($a1, $a2, $string);
echo $result;

Add owl carousel slider in your website

Add owl carousel slider in your website

<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.js"></script>
<script>
jQuery(document).ready(function(){
jQuery("#owl-demo").owlCarousel({
      autoPlay : 4000,
      navigation : false, // Show next and prev buttons
      slideSpeed : 300,
      paginationSpeed : false,
      singleItem:true
 });});
 </script>

<div id="owl-demo" class="owl-carousel owl-theme">
<div class="item"><img src="images/wordpress.jpg" alt="Wordpress"></div>
<div class="item"><img src="images/bootstrap.jpg" alt="Bootstrap"></div>
<div class="item"><img src="images/php.jpg" alt="Php"></div>
<div class="item"><img src="images/designing.jpg" alt="Designing"></div>
<div class="item"><img src="images/ajax.jpg" alt="Ajax"></div>
</div>

Five free wordpress plugins every user should use:


Here are Wordpress Plugins Links

For Comment Spaming:
https://wordpress.org/plugins/akismet/

Search Engine Optimization (SEO)
https://wordpress.org/plugins/wordpress-seo/

Contact Forms Related
https://wordpress.org/extend/plugins/contact-form-7/

Social Networking
https://wordpress.org/plugins/ultimate-social-media-icons/screenshots/

Login Security

https://wordpress.org/plugins/login-lockdown/

Custom function to add website logo from wordpess admin

Here is the Custom function to add website logo from wordpess admin and you need to this script into your theme's functions.php file:


//Add Menu in admin dashboard
function add_theme_menu_item(){add_menu_page("Theme Options", "Theme Options", "manage_options", "theme-panel", "theme_settings_page", null, 99)\}
// Add Html code to that menu
add_action("admin_menu", "add_theme_menu_item");
function theme_settings_page()
{
    ?>
     <div class="wrap">
     <h1>Theme Options</h1>
     <form method="post" action="options.php" enctype="multipart/form-data">
         <?php
             settings_fields("section");
             do_settings_sections("theme-options");    
             submit_button();
         ?>        
     </form>
  </div>
 <?php
}
function logo_display()
{
 ?>
        <input type="file" name="logo" />
        <?php echo "<img style='width:150px; height:150px;display:block;' src='".get_option('logo')."'>";
       
 
}
//Upload Logo
function handle_logo_upload()
{
 global $option;
if($_FILES["logo"]["tmp_name"])
{
$urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
$temp = $urls["url"];
return $temp;
}
return $option;
}
function display_theme_panel_fields()
{
 add_settings_section("section", "Logo Settings", null, "theme-options");

    add_settings_field("logo", "Add Logo", "logo_display", "theme-options", "section");
    register_setting("section", "logo", "handle_logo_upload");
}
add_action("admin_init", "display_theme_panel_fields");
//To get logo src here is the code:

get_option('logo')

Five Free Woocommece addon plugin user should use..

Here are the Five Free Woocommece addon plugin user should use..

Add product slider
https://wordpress.org/plugins/woocommerce-product-slider/
Show cart total in menu bar
https://wordpress.org/plugins/woocommerce-menu-bar-cart/
Strip payment method
https://wordpress.org/plugins/stripe-for-woocommerce/
Minimum purchse
https://wordpress.org/plugins/minimum-purchase-for-woocommerce/
Add sale price in slicky manner

Get Wordpress Posts With Mysql Like Condition

Here is the code to Get Wordpress Posts With Mysql Like Condition:

$today = "top 250";
$sql = "SELECT * FROM wp_posts WHERE post_title LIKE '$today%' and post_type = 'page' limit 1";
$result = $wpdb->get_results($sql) or die(mysql_error());
   foreach($result as $results)
{
echo $results->post_title."<br>";
echo $results->post_content."<br>";
echo get_the_post_thumbnail( $results->ID, 'thumbnail' );
}

Google Map Filter Api Example

Here is Google Map Filter Api Example: