Skip to content

Instantly share code, notes, and snippets.

View schalkburger's full-sized avatar
💪
eat sleep code repeat

Schalk Burger schalkburger

💪
eat sleep code repeat
View GitHub Profile
@schalkburger
schalkburger / sublime-text-remove-comments-javascript
Created February 17, 2015 08:13
Sublime Text regex to remove comments in JavaScript
\/\/.*
@schalkburger
schalkburger / wordpress-category-thumb.php
Created February 17, 2015 08:17
Wordpress category featured image thumbnail
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
<?php the_post_thumbnail('thumbnail'); ?>
<?php else :?>
<img src="<?php bloginfo('template_directory');?>/img/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" />
<?php endif;?>
@schalkburger
schalkburger / wordpress-conditional.php
Created February 17, 2015 08:20
Wordpress display conditional content
<?php // if inside the loop
if ( is_page( array(1, 2, 3) ) ) { ?>
<p>Conditional content to show</p>
<?php } else { }?>
<?php // if outside the loop
global $post;
if ( is_page('5') && $post->post_parent ) { ?>
<p>Conditional content to show</p>
<?php } else { }?>
@schalkburger
schalkburger / wordpress-display-comments.php
Created February 17, 2015 08:53
Wordpress display comments
<?php // Display latest comments for each post on non-single page views
$comment_array = array_reverse(get_approved_comments($wp_query->post->ID));
$count = 1; // Number of comments to display
if ($comment_array) { ?>
<h3><?php comments_number('No comment', '1 comment', '% comments'); ?></h3>
<ul>
<?php foreach ($comment_array as $comment) {
if ($count++ <= 2) { ?>
<li><?php comment_author_link(); ?>: <?php comment_excerpt(); ?></li>
<?php }
@schalkburger
schalkburger / wordpress-manual-ftp-config.php
Created February 17, 2015 09:07
Wordpress manual FTP config
<?php
// Manual Wordpress FTP
define('FS_CHMOD_FILE', 0755);
define('FS_CHMOD_DIR', 0755);
define('FS_METHOD', 'ftpext');
define('FTP_BASE', '/');
define('FTP_CONTENT_DIR', '/wp-content/');
define('FTP_PLUGIN_DIR ', '/wp-content/plugins/');
define('FTP_USER', 'username');
define('FTP_PASS', 'password');
@schalkburger
schalkburger / wordpress-custom-login-logo.php
Last active August 29, 2015 14:15
Wordpress custom login logo
<?php
function custom_login_logo() {
echo '<style type="text/css">
h1 a {background-image: url('.get_bloginfo('template_directory').'/img/login_logo.png) !important; }
</style>';
}
add_action('login_head', 'custom_login_logo');
?>
@schalkburger
schalkburger / wordpress-list-page-children.php
Last active August 29, 2015 14:15
Wordpress list page children content
<?php
$args = array(
'post_type' => 'page',
'numberposts' => 99,
'post_status' => 'publish',
'order' => 'ASC',
'post_parent' => 1, // Any post parent
);
$attachments = get_posts($args);
if ($attachments) {
@schalkburger
schalkburger / wordpress-post-thumbs.php
Created February 17, 2015 09:30
Wordpress post thumbnails featured image reference
<?php add_theme_support( 'post-thumbnails' ); // Add theme post thumbnails support ?>
<?php the_post_thumbnail(); // Display post thumbnail ?>
<?php set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode // Set post thumbnail to 50 x 50 and does a hard crop ?>
<?php add_image_size( 'custom-thumb', 300, 9999 ); //300 pixels wide (and unlimited height) // Set post thumbnail to 300 x any height, no cropping ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'custom-thumb' ); } else { ?> <img src="<?php bloginfo('template_directory');?>/img/thumb-default.png" alt=""/> <?php } ?>
@schalkburger
schalkburger / wordpress-remove-default-gallery-style.php
Created February 17, 2015 09:36
Wordpress remove default gallery style
@schalkburger
schalkburger / wordpress-list-posts.php
Created February 17, 2015 09:38
Wordpress list posts
<?php
if (is_page()) {
$cat=get_cat_ID($post->post_title); // Use page title to get a category ID
$posts = get_posts ("cat=$cat&showposts=3"); // Show 3 posts
if ($posts) {
foreach ($posts as $post):
setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php endforeach;