Skip to content

Instantly share code, notes, and snippets.

View saxap's full-sized avatar
🙃

Sergey Astafev saxap

🙃
View GitHub Profile
@saxap
saxap / modx-snippets.php
Created February 1, 2017 08:53 — forked from christianhanvey/modx-snippets.php
Useful snippets for MODX Revo
Snippet: [[SnippetName]]
Chunk: [[$ChunkName]]
System Setting: [[++SettingName]]
TV: [[*fieldName/TvName]]
Link tag: [[~PageId? &paramName=`value`]]
Placeholder: [[+PlaceholderName]]
<?php
@saxap
saxap / regenrate.php
Created October 16, 2016 10:46
Regenerate attachment on the fly wordpress
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$img_id = get_post_thumbnail_id( $service->ID );
$parsed = parse_url( wp_get_attachment_url( $img_id ) );
$url = ABSPATH . dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) );
$url = str_replace('/', '/', $url);
$attach_data = wp_generate_attachment_metadata( $img_id, $url );
wp_update_attachment_metadata( $img_id, $attach_data );
function set_max_height(elms, addh) {
if (typeof(addh) === 'undefined') addh = 0;
var maxHeight = Math.max.apply(null, elms.map(function (){
return jQuery(this).height();
}).get());
elms.height(maxHeight+addh);
}
add_action( 'template_redirect', 'so16179138_template_redirect', 0 );
function so16179138_template_redirect()
{
if( is_singular() )
{
global $post, $page;
$num_pages = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
if( $page > $num_pages ){
include( get_template_directory() . '/404.php' );
exit;
// only published term
$args = array();
$args['posts_per_page'] = 99999999999;
$args['post_type'] = 'ask';
$args['tax_query'] = array('relation' => 'AND');
$args['tax_query'][] = array(
'taxonomy' => 'qstatus',
'field' => 'id',
'terms' => array(19),
'operator' => 'NOT IN'
// yoast rel fixes
add_filter( 'wpseo_prev_rel_link', 'hide_it');
add_filter( 'wpseo_next_rel_link', 'hide_it');
function hide_it($str) {
if (is_home() || is_post_type_archive('services') || is_post_type_archive('reviews') || is_post_type_archive('contacts')) {
return false;
} else {
$search = array(
'pressroom/news/',
'pressroom/articles/'
function remove_page_from_query_string($query_string) {
if (is_admin()) return $query_string;
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
@saxap
saxap / waitfunctions.js
Created August 30, 2015 18:34
some functions..
var is_ajaxed = false;
$.ajaxSetup({
//async: false
});
$(document).ajaxSend(function() {
console.log( "is_ajaxed." );
is_ajaxed = true;
});
@saxap
saxap / exclude_children.php
Created August 3, 2015 11:18
exclude children posts from parent taxonomy term page
function exclude_children($wp_query) {
if (isset($wp_query->query_vars['tax_name'])) {
$wp_query->set('tax_query', array(array(
'taxonomy' => 'tax_name',
'field' => 'slug',
'terms' => $wp_query->query_vars['tax_name'],
'include_children' => false
)));
}
}
@saxap
saxap / bootstrap_form_validation.js
Last active August 29, 2015 14:25
simple bootstrap form validation on jquery
function checkErrors(el) {
var errors = false
el.find('input, textarea').each(function(){
if ($(this).val() == '') {
$(this).closest('.form-group').addClass('has-error');
errors = true;
} else {
$(this).closest('.form-group').removeClass('has-error');
}
});