Set and show most viewed post on WordPress

Monday, December 28th, 2015 (0 Comment)

To show most viewed post, we will work with two very important features and also very interesting in WordPress. That is Custom Post Field to create a key (meta key) contains data views (meta data) for each post and features create the widget to display a list of cards in order from low to be viewed, together with thumbnails and view count if available.

1. Write function count views

View count function is quite brief because it was simple features, only the following line:

  • line 02: Set up post_views_count variables to check the data in a meta key.
  • line 03: $count_key=post_views_count settings are stored in the table name wp_postmeta. Note that later if you change the name of this key, all values will be reset
  • Line 04-08: Verify post_views_count metakey, if its data is empty, it will proceed to create a meta key new it with post_views_count name. Also set the $count_key variable value is 0
  • Line 09-012: If post_views_count metakey have data then set  $count_key variable will be increased by a value.

For this function to work, you must set the following code in your theme file single.php are using, and to insert in the loop (in pairs while)

2. Write function display most viewed post

Simultaneously insert this paragraph under it to avoid that access double views:

3. Display most viewed post without widget

After installing the Post Meta setPostViews function name “post_views_count” on each post one, then our work is now taking entries list and Order it in the Meta Post severance.

4. Display most viewed post with widget

code generated widget to display top view posted as follows:

5. Insert CSS widget for most viewed post

For the default widget it bananas too, here you have one few short paragraphs to your CSS as the top widget viewed it all with something a little more special. However, because only a demo, so please write your CSS if needed

If you do not want to create a plugin, the content you write in file functions.php.

If you want to create a plugin, the writing function in plugins.php file and insert the following in to plugins.php file to load styles.css file of plugin into theme:

 

 

Tags: ,

Related Posts

wordpress
Why should use WordPress Framework
wordpress
Create responsive menu in wordpress using bootstrap
wordpress
Create breadcrumbs function without plugin
wordpress
Related Posts functions in WordPress without using the plugin

Related Posts

wordpress
Why should use WordPress Framework
wordpress
Create responsive menu in wordpress using bootstrap
wordpress
Create breadcrumbs function without plugin
wordpress
Related Posts functions in WordPress without using the plugin

Leave a Reply

Your email address will not be published. Required fields are marked *