Creating a Daily Bible Verse Widget for Websites

Creating a Daily Bible Verse Widget for Websites

With just a thin line of code, everyone can add a custom, daily Bible verse application to his website. This tool is simple, fast, safe, and accessible.

Many religious or spiritually-oriented websites feature a “Daily Bible Verse” section. Each day new or returning visitors to the website see a new, inspiring bible verse. A web developer seeking to add such a feature can choose from several such widgets available on the web. Most such tools are free and high quality. This tutorial will help the web developer create his own “Daily Bible Verse” widget with just a few lines of programming.

Why Program a “Daily Bible Verse” Widget From Scratch?

Why would a web developer want to create his own “Daily Bible Verse” widget? There are several problems with using tools produced and provided by someone else:

  • The person or organization offering the application may go out of business.
  • Newer versions of the application may introduce unexpected incompatibilities.
  • Foreign code may be a security risk to his webserver.
  • The developer has little or no control over what may be displayed on his website or how it is displayed.

The web developer can produce a simple, fast, safe, and free Daily Bible Verse widget for his website. The only tools he would need are a bible, a text editor, or a webpage editor capable of saving HTML code as pure text. And a hosting web service that allows PHP scripting.

 

An Explanation of the PHP Code

Here is how the “Daily Bible Verse” program will work: the program will ask the operating system for the day of the year, a number from 0 through 365 (counting a leap year). The program will then search for, open up, and display the contents of a file corresponding to the day number.

Here is the code below

  1. < ? php
  2. $today = getdate();
  3. $day=’v’.$today[‘yday’];
  4. echo file_get_contents(‘verses/’.$day);
  5. ? >

Line 1: This tag tells the webserver to expect some PHP code

Line 2: this line gets today’s date

Line 3: here, we get the numerical day of the year. and attach it to the letter v. For example, if today is the 190th day of the year, the file name would be “v190.”

Line 4: this line delivers the data from the disk and performs it

Line 5: this tag signals the end of PHP code

The PHP code is placed into an appropriate part of the web page, wherever the Bible verse is displayed. The output of this application can be styled in any way the developer preferences.

Additional Files Needed by the “Daily Bible Verse” Web Application

The hard part comes in creating the individual verse files. The program requires one bible verse to be made per day of the year. The verses must be uploaded to and stored on the webserver. Including leap years, the developer will need to create 366 files. Each file will contain a short verse like the one below:

It is time-consuming, but there are several benefits in a developer producing her accumulation of verity for her preferred audience:

  • The developer has absolute control.
  • She gets to pick her favorite scriptures.
  • She can pick scripture based upon the seasons or holidays.
  • She can use the Bible version of her choice.
  • She can format the verses in style consistent with the rest of her website.

 

 

 

 

Leave a Reply

Your email address will not be published.