Jump to content

Upcoming events, how?


Roych
 Share

Recommended Posts

Hello all

I'm creating some simple events where every child is a new event. I have start date, content and image field assignet to them. Now I would ilke to show only an upcoming events. Only events that are still to come, so that events older than the (start date) are not shown. I tried to work with THIS but no luck as Im not a coder. :(

Im showing all events like this now:

	<?php foreach ( $pages->find('template=calendar-post, limit=8, sort=Start_date') as $single ):?>

						<div class="calendar-block">


		<a href="<?=$single->url?>"><h6 style="font-size: 14px;font-weight: 400;">
	
			<img height="180" src="<?=$single->Slikces->first->url ?>" alt="<?= $single->Slikces->description->first ?>" style="margin-right: 10px; float: left; object-fit: cover;" width="220px">

			<div class="naslovv"><b><?=$single->title?></b></div></h6>
		</a>


		<div class="ura-datum">

				<span class="ime-dneva"><?php echo strftime("%A", strtotime($single->Start_date)); ?></span> | 
				<i class="fa fa-calendar" aria-hidden="true"></i>&nbsp;&nbsp;
				<?php echo strftime("%d %B", strtotime($single->Start_date)); ?> 
				<?php echo strftime("%Y", strtotime($single->Start_date)); ?> | 
				<i class="fa fa-clock-o">&nbsp;&nbsp;</i> <?php echo strftime("%H:%M", strtotime($single->Start_date)); ?><sup>h</sup> </div>

					<div style="text-align:justify; color:inherit;padding-top:10px;padding-right:10px;"><?=$single->Content?></div><a href="<?= $single->url ?>" class="button read-more-button big button-arrow"><?= $out = __("Read more"); ?></a>
		</div>
	<? endforeach; ?>

I'd like to show upcoming events on another template (homepage) as well.

Any help greatly appreciated ;)

Thank you in advance

R

Link to comment
Share on other sites

<?php foreach ( $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date') as $single ) : ?>

You can use Start_date>=today as a selector to only show items with a Start_date that is either today or in the future.

  • Like 7
Link to comment
Share on other sites

On 11/04/2017 at 10:10 AM, arjen said:

<?php foreach ( $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date') as $single ) : ?>

You can use Start_date>=today as a selector to only show items with a Start_date that is either today or in the future.

Nice! Thanks for sharing @arjen.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hello,

The upper works like a charm but was wondering if it is somehow possible to add some text if there is no upcoming events. like (There is no upcoming events ...) So maybe some if else statements or something, I'm not a coder, but understand a little.

I'm using Start_date>=today option from upper posts to show upcoming events.

	<?php foreach ( $pages->find('template=calendar-post, limit=8, sort=Start_date') as $single ):?>

Thank you

R

Link to comment
Share on other sites

$events = $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date');

if (count($events)) {
	echo "There are events, yes!";
} else {
	echo "Out of luck";
}

Small clue :)

  • Like 1
Link to comment
Share on other sites

It works, but if there is an upcoming event, it also shows me the id number of an event how do I get rid of it. And for multilanguage site I tried 

<?= $out = __('No events at this time.'); ?>

but it's not working. (not that important atm)

Thank you ;)

R

Link to comment
Share on other sites

Hmm... I was to fast it's not working :/ I'm doing something wrong ...

My whole original code looks like this:

<?php foreach ( $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date') as $single ):?>

<!-- Event -->
<li>
<div class="date">
	<span>
		<span class="day"><?php echo strftime("%d", strtotime($single->Start_date)); ?></span>
		<span class="month"><?php echo strftime("%h", strtotime($single->Start_date)); ?></span>
		<span class="year"><?php echo strftime("%Y", strtotime($single->Start_date)); ?></span>
	</span>
</div>
<div class="event-content">
	<h6><a href="<?=$single->url?>"><?=$single->title?></a></h6>
	<ul class="event-meta">
		<li><i class="fa fa-clock-o">&nbsp;&nbsp;</i> <?php echo strftime("%H:%M", strtotime($single->Start_date)); ?><sup><?= $out = __("h"); ?></sup></li>
		<li><i class="icons icon-location"></i> 340 W 50th St.New York</li>
	</ul>
</div>
</li>
<!-- /Event -->

<? endforeach; ?>	

I tried to work with your code but I'm doing it totaly wrong I guess :/

<?= $events = $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date');
if (count($events)) {
   echo '<li>',
		'<div class="date">',
		'<span>',
		'<span class="day">{echo strftime("%d", strtotime($single->Start_date))}</span>',
		'<span class="month">{ echo strftime("%h", strtotime($single->Start_date))}</span>',
		'<span class="year">{ echo strftime("%Y", strtotime($single->Start_date))}</span>',
		'</span>',
		'</div>',
			
		'<div class="event-content">',
		'<h6><a href="<?=$single->url?>"><?=$single->title?></a></h6>',
		'<ul class="event-meta">',
		'<li><i class="fa fa-clock-o">  </i> <?php echo strftime("%H:%M", strtotime($single->Start_date)); ?><sup><?= $out = __("h"); ?></sup></li>',
		'<li><i class="icons icon-location"></i> 340 W 50th St.New York</li>',
		'</ul>',
        '</div>',
		'</li>';
} else {
	echo "<span style='font-size:12px;text-align:center;'>No upcoming events at this time!</span> ";
}
?>	

If I just paste your empty code in I get Id's of articles like   1106|1107|1108 ...

 

Thank you

R

Link to comment
Share on other sites

I'll assume those are two separate code snippets...

In the second snippet, you are assigning the page array to $events, but you are referencing $single from your first snippet.

Also, these lines

'<span class="day">{echo strftime("%d", strtotime($single->Start_date))}</span>'

should not have {echo. I believe you use {} to enclose echo'd variables, and not functions. <-- Don't quote me on that. :)

There is also a mix of shorthand (<?=) and regular (<?php echo). I would use one style everywhere to make it easier to read.

Link to comment
Share on other sites

 

38 minutes ago, rick said:

'<span class="day">{echo strftime("%d", strtotime($single->Start_date))}</span>'

this should be the same as in the first code, I forgot to change it back as I was playing and trying all sorts of things. As I said I'm not a coder so I'm playing around, sorry for that :o

So the first code is the one I'm using to show the events and all is working. All I need is to show the text if there is no upcoming events. Not sure how to put arjen's code together.

thx

R

Link to comment
Share on other sites

@Roych, you might find it easier to stick with your original event markup (i.e. as primarily HTML) rather than echoing the entire event markup in PHP. You can switch in and out of PHP as much as you like, and treat PHP similar to how you would work with a template language like Twig or Smarty:

<?php $events = $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date'); ?>
<?php if(count($events)): ?>
    <?php foreach($events as $single): ?>
        <!-- Event -->
        <li>
            <div class="date">
                <span>
                    <span class="day"><?php echo strftime("%d", strtotime($single->Start_date)); ?></span>
                    <span class="month"><?php echo strftime("%h", strtotime($single->Start_date)); ?></span>
                    <span class="year"><?php echo strftime("%Y", strtotime($single->Start_date)); ?></span>
                </span>
            </div>
            <div class="event-content">
                <h6><a href="<?=$single->url?>"><?=$single->title?></a></h6>
                <ul class="event-meta">
                    <li><i class="fa fa-clock-o">&nbsp;&nbsp;</i> <?php echo strftime("%H:%M", strtotime($single->Start_date)); ?><sup><?= $out = __("h"); ?></sup></li>
                    <li><i class="icons icon-location"></i> 340 W 50th St.New York</li>
                </ul>
            </div>
        </li>
        <!-- /Event -->
    <?php endforeach; ?>
<?php else: ?>
    <p>No upcoming events at this time!</p>
<?php endif; ?>

 

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Hello, I need you help again with this :undecided:

Everything is working fine but I need to put another line of text like "TODAY" if a date is today. 

<?php $events = $pages->find('template=calendar-post, limit=8, Start_date>=today, sort=Start_date'); ?>
<?php if(count($events)): ?>
    <?php foreach($events as $single): ?>
        <!-- Event -->
        <li>
            <div class="date">
                <span>
                    <span class="day"><?php echo strftime("%d", strtotime($single->Start_date)); ?></span>
                    <span class="month"><?php echo strftime("%h", strtotime($single->Start_date)); ?></span>
                    <span class="year"><?php echo strftime("%Y", strtotime($single->Start_date)); ?></span>
                </span>
            </div>
            <div class="event-content">
                <h6><a href="<?=$single->url?>"><?=$single->title?></a></h6>
                <ul class="event-meta">
                    <li><i class="fa fa-clock-o" aria-hidden="true">  </i> <?php echo strftime("%H:%M", strtotime($single->Start_date)); ?><sup><?= $out = __("h"); ?></sup></li>
                
                  
<!--  
<div class='Danes-text'>TODAY!</div>
 -->
                  
                  
				</ul>
            </div>
        </li>
        <!-- /Event -->
    <?php endforeach; ?>
<?php else: ?>
    <div style="font-size: 14px;margin-top:-15px;color: #63b2f5;"><?= $out = __("No upcoming events at this time!"); ?></div>
<?php endif; ?>

You can see where I wan't to put in the TODAY text. Can this be done? I tried if elseif else but no luck. :(

Any ideas how can this be done?

Thank you in advance

R

Link to comment
Share on other sites

What did you try on the if?

It could be something like:

<?php if (date('d-m-Y') == date('d-m-Y', $single->Start_date) : ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

 

  • Like 1
Link to comment
Share on other sites

Thank you for help ;)

I tried something similar, but had no luck. I tried your code It gave error than I realised one ")" was missing. ;) But still not working,  sadly.  Nothing shows up.  Any ideas? ???

<?php if (date('d-m-Y') == date('d-m-Y', $single->Start_date)): ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

This is what I have  now ...

R

Link to comment
Share on other sites

@Roych, if a second argument is given to date() it must be a timestamp. So you need the unformatted value of the date field:

<?php if (date('d-m-Y') == date('d-m-Y', $single->getUnformatted('Start_date'))): ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

 

  • Like 2
Link to comment
Share on other sites

10 hours ago, Robin S said:

@Roych, if a second argument is given to date() it must be a timestamp. So you need the unformatted value of the date field:


<?php if (date('d-m-Y') == date('d-m-Y', $single->getUnformatted('Start_date'))): ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

 

Yes, thank you this one is working perfectly ;) Good to know this, wouldn't have found that one out myself.

Thank you
R

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...