$50
Best Way to Show Upcoming Events + Latest Blog Posts on Homepage
In the left column, I have links to 2 pages: one titled "Fifty-fifty", and the other titled, "Seventy-two".
In the center column, I need to know the cleanest way to automatically display events (sorted by date in order of next upcoming event, and limited to 3 or 4 event listings) that have been entered in the WP backend. I would also like the 'View All Upcoming Events' button to go to a page that lists all upcoming events entered in by the user. I guess that also poses another question... what would be the best way to allow me to enter in events (with date, time, title of events, description, etc.) so that it outputs a list of all upcoming events?
In the right column, I need to automatically list the last 2 blog posts (sorted by most recent, with date and excerpt displayed, but limited by a certain number of words, so that each excerpt is relatively the same height). The user would click on the title of each blog post to read more of the post.
Thanks for your help, and may the best man win!
Spencer Barfuss | 08/13/10 at 2:50pm
| Edit
(5) Possible Answers Submitted...
-

Last edited:
08/13/10
2:59pmGabriel Reguly says:Hi Spencer,
I would try to use http://wordpress.org/extend/plugins/events-calendar/ to manage (insert/edit/delete) the events.
For the posts, surely it is just a matter of knowing how many words you want to show.
Kind Regards,
Gabriel Reguly
- 08/13/10 3:03pm
Spencer Barfuss says:Need more info... it doesn't look like this plugin will allow for a simple list of upcoming events. Looking for some actual code on how to do this...
- 08/13/10 3:23pm
Gabriel Reguly says:Hi Spencer,
Surely I can show some code here, allow me time to do it.
By the way, have you already coded the screenshot or you would you like the code for it too?
Kind Regards,
Gabriel Reguly
- 08/13/10 4:01pm
Spencer Barfuss says:Hi, Gabriel. I already coded the screenshot. I'll give you time to post the code if you'd like. Thanks.
- 08/13/10 10:55pm
Gabriel Reguly says:Hi Spencer,
You will need to add the following code to the events-calendar plugin (it will generate your mark-up)
/**
* Displays the Event Definition List Widget
*
* @author greguly
* @param int $num number of events to list
*/
function displayEventDefinitionList($num) {
global $current_user;
$db = new EC_DB();
$js = new EC_JS();
$options = get_option('optionsEventsCalendar');
$format = $options['dateFormatLarge'];
$day_name_length = $options['daynamelength'];
$events = $db->getUpcomingEvents($num);
$output = '<dl id="events-calendar-list">';
foreach($events as $event) {
if ($event->accessLevel == 'public' || $current_user->has_cap($event->accessLevel)) {
$splitDate = explode("-", $event->eventStartDate);
$month = $splitDate[1];
$day = $splitDate[2];
$year = $splitDate[0];
$timeStp = mktime(0, 0, 0, $month, $day, $year);
$startDate = date("$format", $timeStp );
$PostID = isset($event->postID) ? $event->postID : '';
if ($PostID == '')
$titlinked = $event->eventTitle;
else
$titlinked = '<a title="' . $event->eventTitle . '" href="' . get_permalink($PostID) . '">' . $event->eventTitle . '</a>';
// don't send T\'itles
if (false !== strpos($titlinked, "\'"))
$titlinked = stripslashes($titlinked);
//$startDate = $startDate < date("$format") ? date("$format") : $startDate;
$output .= '
<dt>' . $titlinked. '</dt>
<dd class="ev">' . $startDate . '</dd>
<dd>' . $event->eventDescription . '</dd>';
}
}
$output .= '</dl>';
if ($output == '<dl id="events-calendar-list"></dl>') {
echo '<dl><dt id="no-events-in-list">', __('Events are coming soon, stay tuned!','events-calendar'), '</dt></dl>' ."\n";
} else {
if (false !== strpos($output, "\'")) {
$output = stripslashes($output);
}
echo $output . "\n";
}
}
It should be inserted on file plugins/events-calendar/ec_calendar.class.php, after line 176.
Also you will need to add this code
/**
* Will display an events definition list.
*
* This can be used by themes that are not widget ready.
*
* @param int $num number of events to display. defaults to 5.
*/
function SidebarEventsDefinitionList($num = 5) {
$calendar= new EC_Calendar();
$calendar->displayEventDefinitionList($num);
}
This time the file is plugins/events-calendar/events_calendar.php, after line 343
Now you can use this code to show the next 4 future events.
<div class="boxer events">
<h3>Events</h3>
<?php SidebarEventsDefinitionList(4);?>
</div>
- 08/13/10 3:03pm
-

Last edited:
08/13/10
3:03pmPippin Williamson says:For the left part, use Events Calendar Pro, from Code Canyon:
http://codecanyon.net/item/events-calendar-pro-wordpress-premium-plugin/109301
It's the PRO version of what Gabriel said; a bit more robust and an all around excellent plugin.
For the right section, you could follow this tutorial, if you want to include thumbnails with your excerpts:
http://www.problogdesign.com/wordpress/automatic-wp-thumbnails-proportional-excerpts/
It makes the excerpts and thumbnails match in height.
If you don't want to use thumbnails, use this plugin for the excerpts, it's truly wonderful:
http://www.lucabiagini.com/2008/11/wordpress-plugin-the-excerpt-re-reloaded/- 08/13/10 3:05pm
Pippin Williamson says:For displaying the post in your right section, use this code:
<?php global $post;
$postslist = get_posts('numberposts=2');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<div class="entry">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
<?php endforeach; }
?>
- 08/13/10 3:06pm
Pippin Williamson says:Whoops, forgot the date:
<?php global $post;
$postslist = get_posts('numberposts=2');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<div class="entry">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_time('F jS, Y') ?>
<?php the_excerpt(); ?>
</div>
<?php endforeach; }
?>
- 08/13/10 3:06pm
Spencer Barfuss says:If possible, I'd like to not use a plugin for this, but thanks for the links.
- 08/13/10 3:08pm
Pippin Williamson says:The Events list will require a plugin, unless you want to do some serious coding.
To change the length of the excerpt, put this into your functions.php:
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
return 20; }
Just change "20" to the number of words you'd like. - 08/13/10 3:13pm
Spencer Barfuss says:For some reason, that didn't work. I copied and pasted the code you provided on my index.php page, and then refreshed the page to see what would happen, and I got nothing but a blank page.
Am I missing something in my index.php file?
<?php get_header(); ?>
<div id="slide">
<img src="images/church-sm.jpg" alt="Church on a Hill" />
</div>
<div id="main">
<div id="whitebox">
<div class="boxer lefty">
<h3 class="fifty">Fifty/Fifty</h3>
<p>This past Saturday, we went down to Los Arcos apartments to seek and find little children for our Vacation Bible school. By God's grace, these children heard the message of the gospel loud and clear of the gospel loud and clear loud and clear.</p>
<a title="Fifty-Fifty" href="fifty-fifty" class="more">Read more...</a>
<h3 class="seventy-two">Seventy-Two</h3>
<p>This past Saturday, we went down to Los Arcos apartments to seek and find little children for our Vacation Bible school. By God's grace, these children heard the message of the gospel loud and clear of the gospel loud and clear loud and clear.</p>
<a title="Seventy-two" href="seventy-two" class="more">Read more...</a>
</div>
<div class="boxer events">
<h3>Events</h3>
<dl>
<dt><a title="Lifebridge at Los Arcos" href="events/lifebridge-at-los-arcos">Lifebridge at Los Arcos</a></dt>
<dd class="ev">July 18th, 2010</dd>
<dd>Lifebridge is going out to Los Arcos apartments for 3 days to put on a Vacation Bible school. We could use your help!</dd>
<dt><a title="Bridgeland Outreach" href="events/bridgeland-outreach">Bridgeland Outreach</a></dt>
<dd class="ev">July 18th, 2010</dd>
<dd>Lifebridge is going out to Los Arcos apartments for 3 days to put on a Vacation Bible school. We could use your help!</dd>
<dt><a title="Cypress Creek Lakes VBS" href="events/cypress-creek-lakes-vbs">Cypress Creek Lakes VBS</a></dt>
<dd class="ev">July 18th, 2010</dd>
<dd>Lifebridge is going out to Los Arcos apartments for 3 days to put on a Vacation Bible school. We could use your help!</dd>
</dl>
<a title="View All Upcoming Events" href="events" class="view-events">View All Upcoming Events</a>
</div>
<div class="boxer news">
<h3>News & Blog</h3>
<div class="newpost">
<span class="date">12-11-2010</span>
<h4><a title="Eritrean Vacation Bible School" href="eritrean-vacation-bible-school">Eritrean Vacation Bible School</a></h4>
<p>This past Saturday, we went down to Los Arcos apartments to seek and find little children for our Vacation Bible school. By God's grace, these children heard the message of the gospel loud and clear...</p>
</div>
<div class="newpost">
<span class="date">12-11-2010</span>
<h4><a title="Lifebridge Happenings - September 12th, 2010" href="eritrean-vacation-bible-school">Lifebridge Happenings - September 12th, 2010</a></h4>
<p>This past Saturday, we went down to Los Arcos apartments to seek and find little children for our Vacation Bible school. By God's grace, these children heard the message of the gospel loud and clear...</p>
</div>
<a title="View All Blog Entries" href="/blog/archives" class="view-archives">View All Blog Entries</a>
</div>
</div>
<?php get_footer(); ?> - 08/13/10 3:18pm
Pippin Williamson says:The blank page is caused by a syntax error . . . but the code you pasted doesn't have anything that I gave you, it's just plain html. If you could paste the code that I gave you, from your file, then I can find the solution.
- 08/13/10 3:22pm
Pippin Williamson says:Also, for the events, if you were to purchase the premium plugin, here is the exact code you would need to display events on the homepage:
<?php global $post;
$postslist = sp_get_events($count=1);
foreach ($postslist as $post) :
setup_postdata($post); ?>
<p><a href="<?php the_permalink();?>"><?php the_title();?></a></p>
<p><?php echo sp_get_start_date( $post, $showtime, $dateFormat); ?></p>
<?php endforeach; ?>
And just change $count=1 to what ever number of events you want to show.
- 08/13/10 3:05pm
-

Last edited:
08/13/10
10:46pmAshfame says:Hi Spencer,
For events, you can use any plugin. I use this one - http://meandmymac.net/plugins/events/
And for upcoming posts, you can use this code on a theme page
<?php query_posts('showposts=2'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<span class="datetime"><?php the_time('j. F Y'); ?></span>
<?php ashfame_get_stripped_content(100); ?>
</p>
<?php endwhile;
else: ?><p>No future events scheduled.</p>
<?php endif; ?>
Edited the above code, I thought you wanted to list upcoming posts
Paste this in your functions.php file
function ashfame_get_stripped_content($limit)
{
$content = get_the_content();
$temp = " (<a title=\"Continue Reading..\" href=\"";
$temp = $temp.get_permalink();
$temp = $temp."\">Continue reading →</a>)</p>";
$content = str_replace('</p>',$temp, $content);
echo $content;
}
Also I can give you the line of code which will enable you to embed your events listing anywhere. Let me know if you want me to do so.Previous versions of this answer: 08/13/10 at 3:13pm | 08/13/10 at 3:18pm
- 08/13/10 3:22pm
Spencer Barfuss says:Hey Ashfame, I do want to list the 3 or 4 upcoming FUTURE events in the center column, and then on the right column, I want to display the 2 most recent blog posts to automatically show up.
- 08/13/10 3:23pm
Spencer Barfuss says:So, the right column should display the 2 latest blog posts (past).
- 08/13/10 3:25pm
Ashfame says:Yes! Thats what the code does. It will show the last two posts.
For events, using that plugin and with a single line of code, you can have a listing too. - 08/13/10 3:59pm
Spencer Barfuss says:This is the code that I copied and pasted, and it is not limiting the post.
<?php query_posts('showposts=2'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
<span class="datetime"><?php the_time('j. F Y'); ?></span>
<?php ashfame_get_stripped_content(20); ?></p>
<?php endwhile;
else: ?><p>No future events scheduled.</p>
<?php endif; ?>
I've attached a screenshot...
- 08/13/10 4:14pm
Ashfame says:Ok!
Use this code :
<?php query_posts('showposts=2'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
<span class="datetime"><?php the_time('j. F Y'); ?></span>
<?php the_excerpt(); ?></p>
<?php endwhile;
else: ?><p>No posts found.</p>
<?php endif; ?>
Paste this in your theme's function.php file
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
- 08/13/10 4:17pm
Ashfame says:And regarding the events plugin, create a new page with the content
[events_show]
and it will list all the events coming up.
For showing them as per your screenshot, I will give you the code in a while. - 08/13/10 4:23pm
Spencer Barfuss says:Ashfame, does this events list plugin allow the user to enter in data into text fields in the backend? I want to make sure it's really user-friendly, and does exactly what I'm wanting, which is to display 3 or 4 upcoming FUTURE events, which will then automatically disappear once the events has come and gone. Then, I would like the "View All Upcoming Events" button to go to an Events page that lists ALL upcoming events that have been inputted by the admin.
Thanks for your help! I'm close to giving you the money... - 08/13/10 4:24pm
Spencer Barfuss says:Ok, the most recently updated code you sent for displaying the 2 latest blog posts is NOW WORKING. Thanks! Now, just to figure out what to do for the events listing...
- 08/13/10 4:35pm
Ashfame says:Yes! You can configure its output completely from dashboard. Install it and see for yourself.
For a page to show all events, use the shortcode[events_show]
The above should be in the content of the page.
And regarding for showing it on a theme page (3-4 listings), give me a few minutes, I will give you the code. - 08/13/10 4:44pm
Ashfame says:For showing events as per the screenshot, use this code
echo do_shortcode('[events_show amount="2"]');
Change the value here as per your needs. - 08/13/10 4:45pm
Ashfame says:And for your further reference :
Show a list of events on a page (default)
1. Create a new page.
2a. To show just events put in the page field:
[events_show]
OR
[events_show type="default"]
2b. To also show the archive, put in the page field:
[events_show type="archive"]
2c. And to show todays Events, put in the page field:
[events_show type="today"]
2d. Or to show a weeks worth of Events, put in the page field:
[events_show type="week"]
3. Save the page.
Customized lists (advanced)
Show a specific category:
[events_show category="2"]
Show a specific event:
[events_show type="default" event="9"]
To show just 2 events on your page use:
[events_show type="today" amount="2"]
To also show override the sort order:
[events_show type="default" order="thetime ASC"]
Or a combination:
[events_show type="archive" amount="15" order="ID ASC"]
Note: For the 'order' field review the table and use a table field name and ASC (ascending) DESC (descending), make no mistake here! - 08/13/10 8:21pm
Spencer Barfuss says:I'm liking this solution so far. Although, when I installed the plugin, and then added an event, it's showing up in the header of every page, and not sure why... do you know why it might be doing that?
- 08/13/10 3:22pm
-

Last edited:
08/13/10
5:31pmThiago Fernandes says:No need for a plugin or serious coding on the events too. At least if you agree to use Custom Fields.
Set up a category named 'events' and put a custom-field on your post named 'event-date'. Use the date syntax 'mm/dd/yyyy'.
At your home-template use (edit) the following code.
For the 'view-all-events' You should just remove the 'LIMIT' instruction line from the $querystr var, so it'll show up all upcoming events.
You can use other custom fields just by inputing them on the post and manipulating the $custom_fields var-array at the_loop (foreach).
<?php
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta wpostmeta
ON wposts.ID = wpostmeta.post_id
WHERE wpostmeta.meta_key = 'event-date'
AND STR_TO_DATE(wpostmeta.meta_value, '%m/%d/%Y') >= '".date('Y-m-d')."
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
GROUP BY wposts.ID
ORDER BY STR_TO_DATE(wpostmeta.meta_value, '%m/%d/%Y') ASC
LIMIT 4
";
$events = $wpdb->get_results($querystr, OBJECT);
if (!$events)
echo "<p>Nothing scheduled.</p>";
else {
?>
<ul class="event-list">
<?php
foreach ($events as $post) {
setup_postdata($post);
$custom_fields = get_post_custom();
//make datetime
$arr = explode('/', $custom_fields['event-date']);
$date = mktime(0,0,0,$arr[0], $arr[1], $arr[2]);
?>
<li>
<div class="event-header">
<div class="event-month">
<?php echo date('F', $date) ?>
</div>
<div class="event-title">
<?php the_title(); ?>
</div>
</div>
<?php the_excerpt(); ?>
</li>
<?php
}
?>
</ul>
<?php
}
?>
Your another request (blog posts) should be done with get_posts on that manner:
Set up a 'blog' category and implement this simple piece of code (the_loop)
<?php
$blog = get_posts('category_name=blog&numberposts=2');
foreach ($blog as $post) {
setup_postdata($post);
?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="content-title">
<h3 class="storytitle">
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</h3>
<small><?php
//echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' atrĂ¡s';
the_time('d \d\e M, Y')
?></small>
</div>
<?php edit_post_link('<p style="float:right;">Edit</p>', '', ''); ?>
<div class="storycontent">
<?php the_excerpt(); ?>
<a class="link-more" href="<?php the_permalink(); ?>" title="See full article">Continue...</a>
</div>
</div>
<?php } ?>
RegardsPrevious versions of this answer: 08/13/10 at 4:47pm | 08/13/10 at 4:55pm | 08/13/10 at 4:56pm | 08/13/10 at 4:58pm | 08/13/10 at 5:31pm
-

Last edited:
08/13/10
10:46pmAndrew C says:I did this via meta-data. http://bit.ly/93VHUh
really simple to implement..
I can set this up for you within 30 minutes.Previous versions of this answer: 08/13/10 at 7:58pm | 08/13/10 at 8:00pm | 08/13/10 at 8:02pm | 08/13/10 at 10:45pm
- 08/13/10 10:44pm
Spencer Barfuss says:Awesome! Thank you so much. Worked great. Congrats!
- 08/13/10 10:44pm
This question has expired.
Current status of this question: Completed





