Plugin Directory

Changeset 2624971


Ignore:
Timestamp:
11/05/2021 08:29:27 AM (4 years ago)
Author:
dannywpthemes
Message:

v-1.0.3 - Add post view to posts

Location:
aztheme-toolkit/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • aztheme-toolkit/trunk/aztheme-toolkit.php

    r2621903 r2624971  
    9595}
    9696
     97/**
     98 * Count Post Visits
     99 */
     100function aztheme_toolkit_count_post_visits()
     101{
     102    if( is_single() )
     103    {
     104        global $post;
     105        $views = get_post_meta( $post->ID, 'producta_post_viewed', true );
     106        if ( $views == '' ) {
     107            update_post_meta( $post->ID, 'producta_post_viewed', '1' );
     108        } else {
     109            $views_no = intval( $views );
     110            update_post_meta( $post->ID, 'producta_post_viewed', ++$views_no );
     111        }
     112    }
     113}
     114
     115add_action( 'wp_head', 'aztheme_toolkit_count_post_visits' );
     116
     117// Get Post View
     118function aztheme_toolkit_get_post_view()
     119{
     120    global $post;
     121    $view = get_post_meta( $post->ID, 'producta_post_viewed',true);
     122    $view = (int)$view;
     123    if ($view > 1 ) {
     124        $view = $view . ' ' . esc_html__( 'views', 'producta' );
     125    } elseif ( $view == 1) {
     126         $view = $view . ' ' . esc_html__( 'views', 'producta' );
     127    } else {
     128        $view = '0'. ' ' . esc_html__( 'views', 'producta' );
     129    }
     130
     131    return $view;
     132}
     133
     134
    97135if ( ! function_exists( 'aztheme_toolkit_load_scripts' ) ) {
    98136    /**
  • aztheme-toolkit/trunk/readme.txt

    r2621903 r2624971  
    44Tags: toolkit, aztheme, categories, images, social, share
    55Requires at least: 5.0
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77Tested up to: 5.8
    88Requires PHP: 7.4
     
    3333
    3434== Changelog ==
     35= 1.0.3 =
     36* Released: November 05, 2021
     37- Add post view to posts
    3538
    3639= 1.0.2 =
Note: See TracChangeset for help on using the changeset viewer.