WordPress Complete by Hayder Hasin

WordPress Complete by Hayder Hasin

Author:Hayder, Hasin [Hasin Hayder]
Language: eng
Format: epub
Publisher: Packt Publishing


Step 11: Top Ranked Book List

This is a slightly tough part of this chapter. To display some books as top-listed books we have several options. We may create a manual list by editing the sidebar; however, it will not be dynamic at all and is not an acceptable solution. A better solution is to create a real top books list by counting the number of views of each book and dynamically displaying them. For this purpose, we need to create a plug-in on our own. Don't worry, we will keep it simple.

To make this plug-in work properly, we have to store the number of hits in persistent storage, that is where we can re-use them. You can use the database for storing them and that will be the best solution. However, as we are going for a simple plug-in, we will be using a simple text file for this purpose; but remember to use the database (either MySQL or SQLite) wherever possible. If you are already familiar with PHP coding, you can modify the code to suit any database table instead of a flat file.

Now we will design a plug-in, which adds a one pixel by one pixel image to the content of every post dynamically. The image will refer to a PHP file that will act as a hit counter after each call. The following code explains this:

<? /* Plugin Name: Hit Counter Plugin URI: Uh.. No URL Description: A plugin which counts the number of times a post been viewed Author: Hasin Hayder Version: 1.0 Author URI: http://hasin.wordpress.com */ ?> <? add_filter("the_content","HitCount"); function HitCount($content) { global $id; $categories = get_the_category(); foreach($categories as $category) { if ($category->cat_name=="All Books") return $content."<img style='display:none ' src='http://wordpress_url/hitcount.php?id={$id}'>; } return $content; ?>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Deep Learning with Python by François Chollet(12595)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7792)
Grails in Action by Glen Smith Peter Ledbrook(7705)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6427)
Kotlin in Action by Dmitry Jemerov(5076)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3864)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3338)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(3093)
Mastering Bitcoin: Programming the Open Blockchain by Andreas M. Antonopoulos(2873)
The Art Of Deception by Kevin Mitnick(2615)
Drugs Unlimited by Mike Power(2475)
The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution by Walter Isaacson(2374)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2317)
A Blueprint for Production-Ready Web Applications: Leverage industry best practices to create complete web apps with Python, TypeScript, and AWS by Dr. Philip Jones(2287)
Writing for the Web: Creating Compelling Web Content Using Words, Pictures and Sound (Eva Spring's Library) by Lynda Felder(2268)
SEO 2018: Learn search engine optimization with smart internet marketing strategies by Adam Clarke(2197)
JavaScript by Example by S Dani Akash(2141)
DarkMarket by Misha Glenny(2086)
Wireless Hacking 101 by Karina Astudillo(2083)
Hands-On Cybersecurity with Blockchain by Rajneesh Gupta(2010)