Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Tuesday, December 23, 2014

Some important tools of wordPress

How to dynamic WordPress search option:

<form action="<?php echo home_url(); ?>/" method="post" role="form" class="pull-right search-form col-xs-12 col-sm-3" id="searchform">
                            <div class="form-group">
                               
                                    <input type="text" class="form-control" id="search-form" placeholder="To search type and hit enter" value="<?php esc_attr_e( 'Search', 'brightpage' ); ?>" name="s" id="s" onfocus="if (this.value == '<?php esc_attr_e( 'Search', 'brightpage' ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php esc_attr_e( 'Search', 'brightpage' ); ?>';}" />
                                    <input type="submit" id="searchsubmit" value="<?php esc_attr_e( 'Go', 'brightpage' ); ?>" />
                            </div>
</form>

how to active dynamic breadcrumbs in WordPress:
firstly copy below this code and paste where you want to breadcrumbs:

<div class="breadcumbs">
                            <?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?></div>

Next you copy below this code and paste function.php:

<?php
function wordpress_breadcrumbs() {

  $delimiter = '&raquo;';
  $name = 'Home'; //text for the 'Home' link
  $currentBefore = '<span class="current">';
  $currentAfter = '</span>';

  if ( !is_home() && !is_front_page() || is_paged() ) {

    echo '<div id="crumbs">';

    global $post;
    $home = get_bloginfo('url');
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';

    if ( is_category() ) {
      global $wp_query;
      $cat_obj = $wp_query->get_queried_object();
      $thisCat = $cat_obj->term_id;
      $thisCat = get_category($thisCat);
      $parentCat = get_category($thisCat->parent);
      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
      echo $currentBefore . 'Archive by category &#39;';
      single_cat_title();
      echo '&#39;' . $currentAfter;

    } elseif ( is_day() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('d') . $currentAfter;

    } elseif ( is_month() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('F') . $currentAfter;

    } elseif ( is_year() ) {
      echo $currentBefore . get_the_time('Y') . $currentAfter;

    } elseif ( is_single() ) {
      $cat = get_the_category(); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && !$post->post_parent ) {
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_search() ) {
      echo $currentBefore . 'Search results for &#39;' . get_search_query() . '&#39;' . $currentAfter;

    } elseif ( is_tag() ) {
      echo $currentBefore . 'Posts tagged &#39;';
      single_tag_title();
      echo '&#39;' . $currentAfter;

    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;

    } elseif ( is_404() ) {
      echo $currentBefore . 'Error 404' . $currentAfter;
    }

    if ( get_query_var('paged') ) {
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
      echo __('Page') . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
    }

    echo '</div>';

  }
}

?>

How you can active post-loop.php in wordpress:

<?php if(have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>   
        <div class="">.........some content......</div>
                       
    <?php endwhile; ?>   
<?php endif; ?>

Monday, December 22, 2014

WordPressc single page, archive page and 404 page

To enable comment: 

functions.php function comment_scripts(){
if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
}
add_action( 'wp_enqueue_scripts', 'comment_scripts' ); 
To enable featured image: 

functions.php 

add_theme_support( 'post-thumbnails', array( 'post' ) ); 

To enable crop feature: 

functions.php

set_post_thumbnail_size( 200, 200, true );
add_image_size( 'post-image', 150, 150, true ); 

Using Featured Image:

functions.php

add_theme_support( 'post-thumbnails', array( 'post' ) ); 
<?php the_post_thumbnail('post-general-thumb', array('class' => 'img-responsive ')); ?>

single.php in WordPress:

<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php _e('404 Error: Not Found'); ?>
<?php endif; ?> 

archive.php in WordPress:

for Archive & Archive Post List

  <h1>
<?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */ if (is_category()) { ?>
<?php _e('Archive for the'); ?> '< ?php echo single_cat_title(); ?>' < ?php _e('Category'); ?>
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<?php _e('Archive for the'); ?> < ?php single_tag_title(); ?> Tag
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<?php _e('Archive for'); ?> < ?php the_time('F jS, Y'); ?>
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<?php _e('Archive for'); ?> < ?php the_time('F, Y'); ?>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<?php _e('Archive for'); ?> < ?php the_time('Y'); ?>
<?php /* If this is a search */ } elseif (is_search()) { ?>
<?php _e('Search Results'); ?>
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<?php _e('Author Archive'); ?>
<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<?php _e('Blog Archives'); ?>
<?php } ?>

For archive post query: <?php get_template_part( 'post-excerpt' ); // Post Excerpt (post-excerpt.php) ?>  

If no post in archive or 404:

<?php else : ?> <h3>< ?php _e('404 Error: Not Found'); ?>
<?php endif; ?>  

404.php in WordPress:

<h2>404 Error: Not Found
<p>Sorry, but the page you are trying to reach is unavailable or does not exist.< /p > 

 Post Query in index.php:

<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
       <div class="some">...............</div>
<?php endwhile; ?>
<?php endif; ?> 

Pagination in index.php:

<div class="nav-previous">
<?php next_posts_link( __( '< span class="meta-nav">← Older posts') ); ?>
</div>< div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→') ); ?>
  </div>  

Activate Option Tree: 

functions.php

add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
include_once( 'option-tree/ot-loader.php' );
include_once( 'includes/theme-options.php' ); 

 Some important tools:

<?php the_permalink(); ?>=link dynamic

Wordpress conditional and custom post registration

Document needs for simple dynamic slider:

All are implement in function.php

slider:

add_action( 'init', 'slider_custom_post' );
function slider_custom_post() {
register_post_type( 'slider-items',
array(
'labels' => array(
'name' => __( 'slider' ),
'singular_name' => __( 'slide' ),
'add_new_item' => __( 'Add New slider' )
),
'public' => true,
'supports' => array('author', 'thumbnail', 'title'),
'has_archive' => true,
'rewrite' => array('slug' => 'slider-item'),
)
);
}

 add image croping in function.php:

add_image_size( 'slider-image', 1900, 654, true );

 add image support:

Add below this code in your  slider.php:

<?php
global $post;
$args = array( 'posts_per_page' => -1, 'post_type'=> 'slider-items');
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>

  <li data-thumb="< ?php echo $slider_image[0]; ?>">
<?php the_post_thumbnail('slider-image'); ?>

<?php endforeach; ?>

page.php script: if you want to dynamic page in your blog or website you copy below this code and paste in your page.php: 

 <?php get_header();?>
<?php if(have_posts()) : ?>< ?php while(have_posts()) : the_post(); ?>

<div class="row">
<div class="col-sm-12">
<?php the_content(); ?>
</div>

</div>
<?php endwhile; ?>

<?php else : ?>
<div class="post">
<h3>< ?php _e('404 Error: Not Found', 'brightpage'); ?>
</div>
<?php endif; ?> 

 Active jquery from Wordpress:

if you want to active wordpress jquery in your website then you copy below this code and paste in function.php

/*for calling jquery*/
function latest_jquery_call() {
wp_enqueue_script('jquery');
}
add_action('init', 'latest_jquery_call');  

Simple Dynamic menu: 

if you want to active dynamic menu in your blog then you type below this code location  this: 

function.php

// This theme uses wp_nav_menu() in one location.

register_nav_menus( array(
'mainmenu' => __( 'Mainmenu Menu'),
) );

 header.php

<? ?php wp_nav_menu( array( 'theme_location' => 'mainmenu', 'menu_class' => 'container' ) ); ?> 

An amazing read more function:

functions.php

function excerpt($num) {$limit = $num+1; $excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)." < a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read More";
echo $excerpt;
}
Usage: < ?php echo excerpt('15'); ?>


Some important script of wordpress

   Must be important:

<?php bloginfo('name'); ?> = To active blog name
<?php bloginfo('home'); ?> = home option
<?php the_content(); ?> = get content
<?php the_time('d M, Y') ?> =  date
<?php comments_popup_link('0', '1', '%'); ?>= for comment
<?php the_author(); ?> = admin call 
<?php the_excerpt(); ?> = content summery
<?php echo get_template_directory_uri(); ?> = dynamic theme directory
<?php bloginfo('stylesheet_url'); ?> = To get dynamic stylesheet
<?php wp_head(); ?> = To get header script
<?php wp_footer(); ?> = To get footer script
<?php wp_title( '|', true, 'right' ); ?> = For Title Dynamic
<?php echo do_shortcode('[contact-form-7 id="27" title="slider contact"]'); ?>: Shortcode to active for contact 7

Pagination code for post or blog: 

At first you paste below this code in function.php:

function pagination($pages = '', $range = 4)
    {
         
$showitems = ($range * 2)+1;

         global 
$paged;
         if(empty(
$paged)) $paged = 1;

         if(
$pages == '')
         {
             global 
$wp_query;
             
$pages = $wp_query->max_num_pages;
             if(!
$pages)
             {
                 
$pages = 1;
             }
         }

         if(
1 != $pages)
         {
             echo 
"<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
             if(
$paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
             if(
$paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

             for (
$i=1; $i <= $pages; $i++)
             {
                 if (
1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo (
$paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                 }
             }

             if (
$paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
             if (
$paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
             echo 
"</div>\n";
         }
    } 


Then you paste below this code in style.css:


/* For Pagination Css */.pagination{clear:both;font-size:11px;line-height:13px;margin-left:35px;padding:20px 0;
}
.
pagination span, .pagination a{display:block;float:left;margin:2px 2px 2px 0;padding:6px 9px 5px 9px;text-decoration:none;width:auto;color:#fff;background:#555;}
.
pagination a:hover{color:#fff;background:#3279BB;}
.
pagination .current{padding:6px 9px 5px 9px;background:#3279BB;color:#fff;} 


Finally you cope below this code and paste where you can pagination in blog: 

<?php if (function_exists("pagination")) {
        
pagination($additional_loop->max_num_pages);
    } 
?>

Widget Registation in Wordpress:

Firstly you should sidebar registration by below this code:

Sideber.php:

<?php if ( ! dynamic_sidebar( 'sidebar-top' ) ) : ?>
  <p>faridul is not nice boyfaridul is not nice boyfaridul is not nice boyfaridul is not nice boy< /p>
<?php endif; ?>

Nextly you copy below this code and paste in function.php:

* Register sidebars and widgetized areas ********************************************/

function faridul_widget_areas() {
register_sidebar( array(
'name' => __( 'Welcome Text', 'faridul' ),
'id' => 'welcome-text',
'description' => __( 'Plese write document', 'faridul' ),
'before_widget' => '<div class="col-sm-8">',
'after_widget' => '</div>',
'before_title' => '<h2 class="text-title">',
'after_title' => '</h2>',
) );
}
add_action('widgets_init', 'faridul_widget_areas');

 

 

Saturday, December 20, 2014

Awesome WordPress Security Tips

1. Disable your HTTP Trace Method: 
It is prevented when your site attract Cross Site Tracing(XST) . Now you edit .htaccess from your server Apache configuration.

> RewriteEngine On
> RewriteCond %{REQUEST_METHOD} ^TRACE
> RewriteRule .* – [F]

2.Removing holder output form WordPress installation. 
Concerns:  It can prevented your wordpress functionality .Such as if you will use RSS feed ,then you comment this line.

You below's code paste your function.php file.

remove_action(‘wp_head’, ‘index_rel_link’);
remove_action(‘wp_head’, ‘feed_links’, 2);
remove_action(‘wp_head’, ‘feed_links_extra’, 3);
remove_action(‘wp_head’, ‘rsd_link’);
remove_action(‘wp_head’, ‘wlwmanifest_link’);
remove_action(‘wp_head’, ‘parent_post_rel_link’, 10, 0);
remove_action(‘wp_head’, ‘start_post_rel_link’, 10, 0);
remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0);
remove_action(‘wp_head’, ‘wp_generator’);
remove_action(‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0);
remove_action(‘wp_head’, ‘noindex’, 1);

3. Stop comment posting form proxy server.
You add below code in your .htaccess file.for this spam will be reduced 


RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* – [F,NS,L]

4.Change your WordPress default Database prefix
You may be know,WordPress default database prefix is “wp_”. So when you install WordPress for your purpose you change your prefix.Such as "rootitech_" .

5. Deny your danger string query
You add blew code in your .htacces file to prevent your XSS attract.
Inform: Some plugin and theme will not working if you will not deny string.

 <IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ../   [NC,OR]
RewriteCond %{QUERY_STRING} boot.ini [NC,OR]
RewriteCond %{QUERY_STRING} tag= [NC,OR]
RewriteCond %{QUERY_STRING} ftp: [NC,OR]
RewriteCond %{QUERY_STRING} http: [NC,OR]
RewriteCond %{QUERY_STRING} https:   [NC,OR]
RewriteCond %{QUERY_STRING} mosConfig [NC,OR]
RewriteCond %{QUERY_STRING} ^.*([|]|(|)|<|>|’|”|;|?|*).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(%22|%27|%3C|%3E|%5C|%7B|%7C).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(%0|%A|%B|%C|%D|%E|%F|127.0).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(globals|encode|config|localhost|loopback).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(request|select|insert|union|declare|drop).* [NC]
RewriteRule ^(.*)$ – [F,L]
</IfModule>

6. You add PHP Hardening in your System
You install Suhosin PHP Hardening in server system and enable it.For this your system security will be increased.