__( 'Primary Menu', 'thecodingstuff' ),
)
);
add_image_size( 'thecodingstuff-thumbnail', 710, 391, true );
/*-----------------------------------------------------------------------------------*/
/* Activate sidebar for Wordpress use
/*-----------------------------------------------------------------------------------*/
function wordcomat_register_sidebars() {
register_sidebar(array( // Start a series of sidebars to register
'id' => 'sidebar', // Make an ID
'name' => __('Sidebar','thecodingstuff'), // Name it
'description' => __('Take it on the side...','thecodingstuff'), // Dumb description for the admin side
'before_widget' => '
', // What to display before each widget
'after_widget' => '
', // What to display following each widget
'before_title' => '', // What to display before each widget's title
'after_title' => '
', // What to display following each widget's title
'empty_title'=> '', // What to display in the case of no title defined for a widget
// Copy and paste the lines above right here if you want to make another sidebar,
// just change the values of id and name to another word/name
));
register_sidebar(array(
'id' => 'footer',
'name' => __('Footer','thecodingstuff'),
'description' => __('Take it on the footer...','thecodingstuff'),
'before_widget' => '',
'before_title' => '',
'after_title' => '
',
'empty_title'=> '',
));
}
// adding sidebars to Wordpress (these are created in functions.php)
add_action( 'widgets_init', 'wordcomat_register_sidebars' );
/*-----------------------------------------------------------------------------------*/
/* Enqueue Styles and Scripts
/*-----------------------------------------------------------------------------------*/
function wordcomat_enque_scripts() {
wp_enqueue_style('fontawesome_style', get_stylesheet_directory_uri() . '/assets/plugins/font-awesome/css/font-awesome.min.css');
wp_enqueue_style('bootstrap_style', get_stylesheet_directory_uri() . '/assets/plugins/bootstrap/css/bootstrap.min.css');
wp_enqueue_style('wordcomat_style', get_stylesheet_directory_uri() . '/assets/css/wordcomat.css');
wp_enqueue_style('wordcomat_responsive_style', get_stylesheet_directory_uri() . '/assets/css/responsive.css');
wp_enqueue_style('style.css', get_stylesheet_directory_uri() . '/style.css');
wp_enqueue_script( 'bootstrap_scripts', get_template_directory_uri() . '/assets/plugins/bootstrap/js/bootstrap.min.js', array( 'jquery' ), THECODINGSTUFF_VERSION, true );
wp_enqueue_script( 'wordcomat_scripts', get_template_directory_uri() . '/assets/js/wordcomat.js', array( 'jquery' ), THECODINGSTUFF_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'wordcomat_enque_scripts' );
function add_post_formats() {
add_theme_support( 'post-formats', array( 'image' ) );
}
add_theme_support( 'post-thumbnails' );
add_action( 'after_setup_theme', 'add_post_formats', 20 );
function tokenTruncate($string, $your_desired_width) {
$string = strip_tags($string);
$parts = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
$parts_count = count($parts);
$length = 0;
$last_part = 0;
for (; $last_part < $parts_count; ++$last_part) {
$length += strlen($parts[$last_part]);
if ($length > $your_desired_width) { break; }
}
return implode(array_slice($parts, 0, $last_part));
}
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
if( $count > 1 ){
return $count.' Views';
}else{
return $count.' View';
}
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
function converElapsedTime( $datetime, $full = false )
{
$now = new DateTime;
$then = new DateTime( $datetime );
$diff = (array) $now->diff( $then );
$diff['w'] = floor( $diff['d'] / 7 );
$diff['d'] -= $diff['w'] * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach( $string as $k => & $v )
{
if ( $diff[$k] )
{
$v = $diff[$k] . ' ' . $v .( $diff[$k] > 1 ? 's' : '' );
}
else
{
unset( $string[$k] );
}
}
if ( ! $full ) $string = array_slice( $string, 0, 1 );
return $string ? implode( ', ', $string ) . ' ago' : 'just now';
}
// Our filter callback function
function thecodingstuffDateago( $the_date, $d, $post ) {
$date = date( 'Y-m-d h:i:s', strtotime( $the_date ) );
return converElapsedTime($date);
}
add_action( 'get_the_date', 'thecodingstuffDateago',10,3);
add_action( 'the_date', 'thecodingstuffDateago',10,3);
function thecodingstuffTimeago( $the_date, $d ) {
$date = date( 'Y-m-d h:i:s', strtotime( $the_date ) );
return converElapsedTime($date);
}
add_action( 'the_time', 'thecodingstuffTimeago',10,3,2);
add_action( 'get_the_time', 'thecodingstuffTimeago',10,3,2);
function thecodingstuff_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '' . "\n";
}