Custom calendar shows post at current date.
-
So we have made custom calendar using WP Advanced custom fields plugin and some coding in JS and PHP. Right now when you click on calendar date for example on 28 you get redirected to the first post what have set date as 28.02.2019. What we want to do is to redirect to page where you can see all posts what is set in current date.
Our JS code what makes calendar:
//calendar dates var alldates = $('#alldates').data('dates'); var dates = alldates.map(function (d) { return [new Date(d.date_from), new Date(d.date_till), d.date_type] }); var dates_fak = alldates.map(function (d) { return [d.date_month, d.date_day, d.date_year, d.date_url] }); $( "#datepicker" ).datepicker({ inline: true, numberOfMonths: [1, 1], showCurrentAtPos: 0, beforeShowDay: highlightDays, closeText: "Close", prevText: "Last.", nextText: "Next.", currentText: "Today", monthNames: [ ob.jan,ob.feb,ob.mar,ob.apr,ob.mai,ob.jun,ob.jul,ob.aug,ob.sep,ob.okt,ob.nov,ob.dec ], monthNamesShort: [ "Jan","Feb","Mar","Apr","Mai","Jūn","Jūl","Aug","Sep","Okt","Nov","Dec" ], dayNames: [ "svētdiena","pirmdiena","otrdiena","tre?diena","ceturtdiena","piektdiena","sestdiena" ], dayNamesShort: [ "svt","prm","otr","tre","ctr","pkt","sst" ], dayNamesMin: [ ob.sv,ob.pi,ob.o,ob.t,ob.c,ob.pk,ob.s ], weekHeader: "Ned.", dateFormat: "dd.mm.yy", firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: "", onSelect: function(dateText, inst) { for (i = 0; i < dates_fak.length; i++) { if (inst.selectedMonth == dates_fak[i][0] - 1 && inst.selectedDay.replace( /<span>/g, "" ).replace( /<\/span>/g, "" ) == dates_fak[i][1] && inst.selectedYear == dates_fak[i][2]) { window.location.href = dates_fak[i][1]; } } } });
This is sidebar.php what displays calendar and add some options to it.
<?php if ( !is_page( array( 78, 80, 82 ) ) ) { ?> <div class="sidebar-block calendar"> <div id="datepicker"></div> <div class="event-info"> <div class="event-info-on"><?php echo pll__('Active event'); ?></div> <div class="event-info-off"><?php echo pll__('Not active/ already gone'); ?></div> </div> </div> <?php } ?> <?php if ( !is_page( array( 78, 80, 82, 170 ) ) ) { ?> <?php $related_news = get_field('related_news'); if( $related_news ): ?> <div class="sidebar-related"> <div class="sidebar-header-related"><?php echo pll__('Merge posts'); ?></div> <?php foreach( $related_news as $p ): ?> <div> <div class="news-date"><?php echo get_the_date('d | m | Y', $p->ID); ?></div> <div class="news-title"><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a></div> </div> <?php endforeach; ?> <div class="news-all"><a href="<?php echo get_category_link(1); ?> "><?php echo pll__('More posts'); ?></a></div> </div> <?php endif; ?> <?php } ?>
I know that there is probably plugins what we can use but, we have already custom made calendar for us with custom tempalte so we want to stick with our calendar. Some ideas ?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom calendar shows post at current date.’ is closed to new replies.