Skip to content

Instantly share code, notes, and snippets.

@Dimasmagadan
Dimasmagadan / continiue reading
Last active December 24, 2015 09:19
Scrolls to last "scroll position". Uses localStorage.
<a href="javascript:(function(){var v=&quot;1.3.2&quot;;if(window.jQuery===undefined||window.jQuery.fn.jquery&lt;v){var done=false;var script=document.createElement(&quot;script&quot;);script.src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/&quot;+v+&quot;/jquery.min.js&quot;;script.onload=script.onreadystatechange=function(){if(!done&amp;&amp;(!this.readyState||this.readyState==&quot;loaded&quot;||this.readyState==&quot;complete&quot;)){done=true;initMyBookmarklet();}};document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script);}else{initMyBookmarklet();}function initMyBookmarklet(){(window.myBookmarklet=function(){jQuery(&quot;.nextProda&quot;).live(&quot;click&quot;,function(){if(typeof(localStorage)=='undefined'){alert('Ваш браузер не поддерживает localStorage()');}else{jQuery(document).scrollTop(localStorage.getItem('scroll'+encodeURIComponent(window.location.pathname)));}return false;});jQuery(&quot;body&quot;).append('&lt;a href=&quot;#&quot; class=&quot;nextProda&quot; style=&quot;back
@Dimasmagadan
Dimasmagadan / gist:6215721
Last active December 20, 2015 23:49
rewrite rules "/cpt-label/category/slug/"
/*
don't forget to flush permalinks
/cpt-label/category/slug/
*/
function os_part_tags() {
add_rewrite_rule("^cpt-label/([^/]+)/page/([^/]+)/?",'index.php?post_type=cpt-label&cat=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("^cpt-label/([^/]+)/([^/]+)/?",'index.php?cpt-label=$matches[2]','top');
add_rewrite_rule("^cpt-label/?",'index.php?post_type=cpt-label','top');
}
@Dimasmagadan
Dimasmagadan / functions.php
Last active December 31, 2017 13:02
#WordPress: self expiring posts
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
$expirationtime = get_post_custom_values('expiration');
if (is_array($expirationtime)) {
$expirestring = implode($expirationtime);
}
$secondsbetween = strtotime($expirestring)-time();
@Dimasmagadan
Dimasmagadan / WP_Comment_Query.php
Last active December 31, 2017 13:03
#WordPress Comments Query
$args = array(
'author_email' => '',
'ID' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_ID' => '',
$args = array(
'author_email' => '',
'ID' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_ID' => '',
@Dimasmagadan
Dimasmagadan / menu
Created March 4, 2013 17:56
Bootstrap collapsable nav menu
wp_nav_menu( array(
'menu' => 'main-menu',
'container_class' => 'navbar-content nav-collapse collapse',
'menu_class' => 'nav nav-tabs pull-right',
'menu_id' => 'main-menu' )
);
@Dimasmagadan
Dimasmagadan / WP_Query.php
Last active November 21, 2022 06:27 — forked from luetkemj/wp-query-ref.php
#WordPress query with args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
//////Author Parameters - Show posts associated with certain author.