• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Hire Jordan Smith

  • About
  • Portfolio
    • Web Design
    • Logo Design
  • Services
    • All Services
    • Web Design
    • Logo Design
    • SEO Services
    • Web Hosting
    • Local Services
      • Pooler
      • Richmond Hill
      • Hilton Head
      • Hinesville
  • Reviews
  • FAQ
  • Blog
  • Hire Me
HomeBlog Web DevelopmentHow to organize and output events by date in a loop
how-to-organize-and-output-events-

How to organize and output events by date in a loop

Share
Tweet
Share
Pin
0 Shares

So I had a summer festival website where the client requested that I output a title section for each new day of events. Basically, we were outputting little event snippets and the page was very long and we felt like the user was going to get lost in all the upcoming dates.

Because we were outputting the events in a loop, I had to figure out a solution that could accomplish this while running through each event in the loop.

So I whipped up this little snippet to store any values that had already been echoed in the loop.

Then I checked to see if they had already been output.

If not, I output the date and then stored it in the “already echoed” array and moved on.

This is basically a simple way to organize events when there are multiple events in a single day.

<?php
// Example using a while loop (inside WordPress in this case)
$already_echoed = array()
while ( have_posts() ) : the_post();
if (!in_array($date, $already_echoed)) { //check if current date is in the already_echoed array
echo $date;
}
$already_echoed[] = $date; //store all dates in an array to check against.
// Example using a foreach loop
$already_echoed = array();
foreach ($events as $event) {
if (!in_array($event->date, $already_echoed)) {
echo $event->date . "<br />";
}
$already_echoed[] = $event->date;
}
view raw how-to-organize-and-output-events-by-date-in-a-php-loop.php hosted with ❤ by GitHub
Share
Tweet
Share
Pin
0 Shares

Check Out These Related Articles!

  • how-to-register-and-output-
    How to register and output custom genesis sidebars

  • how-to-exclude-specific-
    How to Exclude Specific Categories from the WordPress Loop

    A client of mine is using a Genesis theme with the Genesis Responsive Slider plugin. The category she is using for the slider is "Featured" and she asked that this…

  • quick-wp-query-call
    Quick WP Query Call

    A simple WP Query Call, meant to be grab and go.

  • how-to-remove-the-woocommerce-sorting-dropdown
    How to remove the WooCommerce sorting dropdown

    Looking for a way to remove the WooCommerce sorting dropdown? This is the dropdown that shows up on the WooCommerce product archive pages that allows you to sort your products…

  • how-to-remove-the-woocommerce-results-count
    How to remove the WooCommerce results count

    Looking for a way to remove the WooCommerce results count? This is the result text that shows up on the WooCommerce product archive pages that displays the amount of products…

hjs-avatar-color

Jordan

Owner

Jordan is a web design, developer and SEO based in Savannah, GA. He believes in providing honest and reliable web design services to businesses of any size. Regardless of the size of the project, he seeks to provide consistent quality. Jordan is an Army veteran and is proud to have served his country. He is husband to a beautiful, Godly woman, Megan and father to four beautiful girls: Kaysie, Kinley, Kylee and Katy.

Read More

Follow Jordan: Facebook Twitter

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About Jordan Smith

Hi, I’m Jordan! I design and build quality websites for businesses in Savannah, GA and all over the United States. I have many years of experience producing professional sites for businesses of all shapes and sizes in Savannah and all over the United States.

Now that we’re acquainted, check out my portfolio to view some of my work, learn more about my philosophy or if you’re ready to get started, contact me now to discuss your project!

Popular Articles

Need Quality Website Design? Top Tips Every Business Owner Should Know308 Total Shares
Does Your Web Design Have More Problems Than Visitors? Top 10 Signs Your Site Needs An Overhaul276 Total Shares
8 Web Design Trends That Are Emerging in 2019242 Total Shares
How Quick Do Businesses Recoup the Average Website Cost?223 Total Shares
Top 10 Website Design Mistakes to Avoid212 Total Shares
12 Worst Website Design Mistakes for 2019 – Even The Pros Are Making These!202 Total Shares
Web Design and Seo 101: How Your Company Can Delight Customers and Keep Them Coming Back190 Total Shares
How to Use Web Design for Local SEO Optimization181 Total Shares
The Intertwined Roles of Web Design and SEO178 Total Shares
How Much Does It Cost to Build a Website? The Difference Between Overpaying and Underpaying156 Total Shares

Categories

  • Blogging
  • Marketing
  • SEO
  • Web Design
  • Web Development
    • ACF Development
    • BX Slider
    • Genesis Development
    • Gravity Forms Development
    • jQuery Development
    • Materialize Development
    • WooCommerce Development
    • WordPress Development
  • Web Hosting
Quick Connect

Phone
912-656-6434

Email
jordan@hirejordansmith.com

Address
Hire Jordan Smith, LLC.
580 White Oak Lane
Richmond Hill, GA 31324

  • Facebook
  • Twitter
  • Linkedin
  • Google
  • About
  • Portfolio
  • Services
  • Reviews
  • FAQ
  • Blog
  • Hire Me
  • Sitemap

© 2019 Hire Jordan Smith