Skip to main content

Posts

Showing posts from 2018

Get Custom Taxonomy terms list in wordpress

<?php $wcatTerms = get_terms('intro_category', array('hide_empty' => 0, 'parent' =>0));    foreach($wcatTerms as $wcatTerm) :    ?> <ul>    <li>       <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a>       <ul class="megaSubCat">          <?php             $wsubargs = array(                'hierarchical' => 1,                'show_option_none' => '',                'hide_empty' => 0,                'parent' => $wcatTerm->term_id,                'taxonomy' => 'intro_category'             ...

Add Custom Sections and panel in wordpress customize r

add_action( 'customize_register', 'customizer_test' ); function customizer_test($wp_customize){ $wp_customize->add_panel('some_panel',array(     'title'=>'Panel1',     'description'=> 'This is panel Description',     'priority'=> 10, )); $wp_customize->add_section('section',array(     'title'=>'section',     'priority'=>10,     'panel'=>'some_panel', )); $wp_customize->add_setting('setting_demo',array(     'defaule'=>'a', )); $wp_customize->add_control('contrl_demo',array(     'label'=>'Text',     'type'=>'text',     'section'=>'section',     'settings'=>'setting_demo', ));}

Stickey header

<style type="text/css"> .sticky {   position: sticky;   font-size: 32px;   top: 0;   width: 100%;   height: 100px;   padding: 1em 0;   background: #34495e;   color: white;   text-align: center;  transition: .32s; } .fixed {   font-size: 24px;   position: fixed;   height: 20px;   transition: .25s; } .top {   text-align: center;   background: #2980b9;   color: #fff; } .bottom {   padding: 5em 0;   background: #2980b9;   color: white;   text-align: center; } body {   margin: 0; } :root {   height: 1000%;   font-family: sans-serif; } </style> <div class="top">Scroll \/</div> <div class="sticky">Animated header</div> <div class="bottom">Content</div> <div class="bottom">Content</div> <div class="bottom">By: Felipe Martinin</div> <script type="text/...

Get Product Price by id woocommerce

Add this code in function.php function woocommerce_price_by_id_wps( $atts ) {     $atts = shortcode_atts( array(         'id' => null,     ), $atts, 'bartag' );     $html = 'Add product id';     if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){          $_product = wc_get_product( $atts['id'] );          if (isset($_product) && !empty($_product)) {           $html = "price = " . $_product->get_price_html();          } else {           $html =  "Wrong product id";          }             }     return $html; } add_shortcode( 'woocommerce_price', 'woocommerce_price_by_id_wps' ); Shortcode  [woocommerce_price id="29"] ===========================================...

Woocommerce Get product from custom texonomy

<?php  $catid = $_POST['catid']; $designid = $_POST['designid']; $args = array( 'post_type' => 'product', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'design', 'field'    => 'slug', 'terms'    => $designid, ), array( 'taxonomy' => 'product_cat', 'field'    => 'term_id', 'terms'    => $catid, ), ), ); $query = new WP_Query( $args ); if( $query->have_posts() ) { while ( $query->have_posts() ) : $query->the_post(); ?> <?php wc_get_template_part( 'content', 'single-product' ); ?> <?php endwhile; } else { echo "No Product Found"; } ?>

How to Fix the HTTP Image Upload Error in WordPress

Increase WordPress Memory Limit 1 define( 'WP_MEMORY_LIMIT' , '256M' ); Change Image Editor Library Used by WordPress 1 2 3 4 5 6 7 function wpb_image_editor_default_to_gd( $editors ) {      $gd_editor = 'WP_Image_Editor_GD' ;      $editors = array_diff ( $editors , array ( $gd_editor ) );      array_unshift ( $editors , $gd_editor );      return $editors ; } add_filter( 'wp_image_editors' , 'wpb_image_editor_default_to_gd' ); Using The .htaccess Method 1 SetEnv MAGICK_THREAD_LIMIT 1

Add pagination on Categories

    <?php     if ( get_query_var( 'paged') )     $paged = get_query_var('paged');     else if ( get_query_var( 'page') )     $paged = get_query_var( 'page');     else     $paged = 1;         $per_page    = 5;     $number_of_series = count( get_terms( 'category') );     $offset  = $per_page * ( $paged - 1);         // Setup the arguments to pass in     $args = array(     'offset'      => $offset,     'number'      => $per_page,     'hide_empty'=>'0'     );         // Gather the series     $series = get_terms( 'category', $args );         // Loop through and display the series     foreach($series as $s)     {     $theurl = get_term_link($s, 'category')...

Get Child Category of a category wordpress

 <?php             $catid = get_queried_object()->term_id;             $args = array('child_of' => $catid);             $categories = get_categories( $args );              if ($categories) {             foreach($categories as $category) {                 echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';                 echo '<p> Description:'. $category->description . '</p>';                 echo '<p> Post Count: '. $category->count . '</p>';              } ...

Add custom Logo in Theme Wordpress

Add this code in function.php file function m1_customize_register( $wp_customize ) {     $wp_customize->add_setting( 'theme_logo' ); // Add setting for logo uploader               // Add control for logo uploader (actual uploader)     $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'theme_logo', array(         'label'    => __( 'School Featured Image', 'm1' ),         'section'  => 'title_tagline',         'settings' => 'theme_logo',     ) ) ); } add_action( 'customize_register', 'm1_customize_register' ); Get logo $theme_logo_url = get_theme_mod( 'theme_logo'); 

get custom post type top level categories

<?php $taxonomy = 'custom_taxonomy_name'; //Choose the taxonomy $terms = get_terms( $taxonomy ); //Get all the terms foreach ($terms as $term) { //Cycle through terms, one at a time // Check and see if the term is a top-level parent. If so, display it. $parent = $term->parent;  if ( $parent=='0' ) { $term_id = $term->term_id; //Define the term ID $term_link = get_term_link( $term, $taxonomy ); //Get the link to the archive page for that term $term_name = $term->name; echo '<a class="ccats" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>'; } } ?>

Get Woocommerce top level categories

<ul class="topcategories"> <?php $get_featured_cats = array( 'taxonomy'     => 'product_cat', 'orderby'      => 'name', 'hide_empty'   => '0', 'include'      => $cat_array ); $all_categories = get_categories( $get_featured_cats ); $j = 1; foreach ($all_categories as $cat) { $parent = $cat->parent;  if ( $parent=='0' ) { echo "<li>"; $cat_id   = $cat->term_id; $cat_link = get_category_link( $cat_id ); $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); // Get Category Thumbnail $image = wp_get_attachment_url( $thumbnail_id ); if ( $image ) { echo '<img src="' . $image . '" alt="" />'; } echo "<br>"; echo $cat->name; // Get Category Name echo "<br>"; echo $cat->description; // Get Category Description $j++; ...

Change date format to time ago WordPress

  /* Function which displays your post date in time ago format */ function meks_time_ago ( ) { return human_time_diff ( get_the_time ( 'U' ) , current_time ( 'timestamp' ) ) . ' ' . __ ( 'ago' ) ; }   2 3 4 5 6 7 8 9   <?php if ( have_posts ( ) ) : ?> <?php while ( have_posts ( ) ) : the_post ( ) ; ?> <?php the_title ( ) ; /* post title */ ?> <?php echo meks_time_ago ( ) ; /* post date in time ago format */ ?> <?php the_content ( ) ; /* post content */ ?> <?php endwhille ( ) ; ?> <?php endif ; ?> For More details Read this https://mekshq.com/change-wordpress-date-format-to-time-ago/