Skip to content

Instantly share code, notes, and snippets.

View mikeott's full-sized avatar
😀
Greetings programs. See you on the grid.

Michael Ott mikeott

😀
Greetings programs. See you on the grid.
View GitHub Profile
@mikeott
mikeott / responsive-table.css
Created June 29, 2023 06:30
Responsive tables
@media screen and (max-width: 600px) {
table {
width: 100%;
border-collapse: collapse;
}
tr:nth-child(even) {
background-color: #f0f0f0;
}
@mikeott
mikeott / timezone.php
Created June 15, 2023 05:23
Timezone
<?php date_default_timezone_set('Australia/Perth'); ?>
@mikeott
mikeott / WordPress - make specific post always be the latest.php
Created June 12, 2023 02:19
WordPress - make specific post always be the latest
/*
Change the date of post ID 946 to the current date.
This is so the post is shown as the latest, thereby showing as the
latest post on the homepage and also as the latest post on the latest-news page.
*/
function update_post_date_daily() {
$post = get_post(946);
@mikeott
mikeott / load-posts-with-ajax-on-click.md
Last active May 26, 2023 07:22
Load posts using AJAX on click

Load posts onclick with AJAX.

Add to page template

<div id="post-container">
 /* Post titles will be inserted here */
</div>

<button id="load-more">Load More</button>
@mikeott
mikeott / php-version-compare.php
Created March 19, 2023 09:43
PHP version compare
if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
echo 'I am using PHP 5, my version: ' . PHP_VERSION . "\n";
@mikeott
mikeott / js-do-something-when-element-is-in-viewport.js
Last active February 22, 2023 03:11
JS do something when element is in viewport
$(window).scroll(function() {
var top_of_element = $("#my_element").offset().top;
var bottom_of_element = $("#my_element").offset().top + $("#my_element").outerHeight();
var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
var top_of_screen = $(window).scrollTop();
if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
// element is in view, do something
} else {
// element is out of view, do something else
@mikeott
mikeott / wordpress-shortcode-for-template-and-editor-usage.php
Created February 20, 2023 05:14
WordPress shortcode for template and editor usage
<?php /*
Board of Directors.
Template usage: <?php echo do_shortcode('[board_of_directors]'); ?>
Editor usage: Add a shortcode: [board_of_directors]
*/
function board_of_directors_code() {
if( have_rows('directors', 19) ) {
while( have_rows('directors', 19) ) : the_row();
@mikeott
mikeott / compare-versions.php
Last active January 19, 2023 01:36
PHP version compare
<?php
$current_version = '1.4.0';
$required_version = '3.9.2';
if (version_compare($current_version, $required_version) < 0) {
// Do something
}
?>
@mikeott
mikeott / if-checkbox-is-ticked.js
Created January 5, 2023 04:05
If checkbox is ticked
if( $('.finished-auctions').is(':checked') ) {
// Do something
}