Skip to content

Instantly share code, notes, and snippets.

@dylan-k
dylan-k / wordpress-post-metadata.php
Last active October 20, 2021 18:22
Wordpress Post Metadata Snippet
<?php
/*
Snippet Name: Dylan's Post-Metadata Snippet for Wordpress.
Description: Shows the date with lots of extra features. the year links to the year, the month to the month, the day to the day. with a plugin, you can also show details like "late in the evening" and "two years ago"
Dependencies:
http://wordpress.org/plugins/when/
http://wordpress.org/extend/plugins/wp-days-ago/
Usage:
I like to store this file in /theme/templates/parts/post-meta.php
then i can just do this to bring it up: <?php get_template_part( '/templates/parts/post', 'meta' ); ?>
@dylan-k
dylan-k / wordpress-conditional-sidebar.php
Last active October 20, 2021 18:22
Conditional Wordpress Sidebar
<?php /* If this is home */ if (is_home()) { ?>
<p style="margin-top: 0pt;"><?php bloginfo('description'); ?> <a href="/about/" title="Read about this website.">More...</a></p>
<?php /* If this is a category archive */ } elseif (is_page()) { ?>
<p style="margin-top: 0pt;"><?php bloginfo('description'); ?> <a href="/about/" title="Read about this website.">More...</a></p>
<a href="http://www.nocategories.net/about/dylan/" title="About Dylan"><img width="100%" src="http://www.nocategories.net/wp-content/themes/eightface/img/dylanprofile.jpg"></a>
<p><?php the_author_description(); ?></p>
<?php /* If this is a category archive */ } elseif (is_category()) { ?>
<p style="margin-top: 0pt;">These entries are part of the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog. You are currently browsing the archives for the <?php single_cat_title(''); ?> topic. <strong>The title of each entry is a link to its full text.</strong></p>
@dylan-k
dylan-k / writers-database_data-model.md
Last active December 24, 2015 23:19
database design for writer's database
@dylan-k
dylan-k / filename-firstline.sh
Created September 12, 2013 00:55
rename each text file according to its first line of text
#A shell script that will rename all the text files in a directory
#each file will be named with the first line of text from that file
for file in *
do
# Avoid renaming diretories!
if [ -f "$file" ]
then
newname=`head -1 $file`
if [ -f "$newname" ]
@dylan-k
dylan-k / batch-suffix
Created September 11, 2013 01:38
add .txt suffix to a batch of files
if you have a batch of files and they all have filenames like poem_01 for example, here's a way to add .txt to the end of all those filenames
for file in poem_*
do
mv "$file" "$file.txt"
done
@dylan-k
dylan-k / splitfiles.md
Last active December 22, 2015 19:09
split one text file into many

if you want to split one text (or html or similar) file into many, here's a trick:

split -p '^plop' file.txt newfile-

...will split file.txt whenever a line starts with 'plop', into files with names like newfile-a, newfile-b, newfile-c, and so on...

I'd love to get it to create numbered files, instead of lettering them a, b, c for extra credit, I'd love to change the filename to be the first line of text

@dylan-k
dylan-k / filenames.txt
Created September 1, 2013 01:36
use windows command prompt to generate a list of filenames
1) Drop to DOS prompt (Start->Run; cmd) or shift-rightclick to "open cmd prompt here"
2) Change to the directory you wish to get a text-based file listing (via cd commands)
3) Run “dir *.* /b >fileListing.txt“
/b puts the directory listing into “Bare Mode”–
@dylan-k
dylan-k / display-modified-time.php
Created August 1, 2013 21:09
Wordpress: Display Modified Time For example, if you posted an article on July 19, 2009, and you found out three days later that there was an update to the story. You can just edit the article, and it will show July 22, 2009 at the timestamp for last update. First you need to open these three files: index.php single.php page.php
<!--Then you will need to locate the following code -->
<?php the_modified_time('F jS, Y');?>
<!--Note: Since there are so many formats of displaying dates, you might not see the exact code, but something along this line.
Replace it with:-->
<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
@dylan-k
dylan-k / delete-blank-lines
Created August 1, 2013 19:08
Sublime Text 2: How to delete blank/empty lines
Select the text
Press Ctrl + H (or click Find->Replace)
Make sure you have selected 'regular expression' (press Alt + R)
Find what: ^\n
Replace With: (nothing, leave in blank)
@dylan-k
dylan-k / redirect.aspx
Last active February 1, 2016 21:08
Redirect
redirect
REDIRECT This is some language for use in an .aspx file. It will send a 301 "moved" response and redirect to the location of your choosing. Just change that URL in there to whatever you want.
<%
Response.Status="301 Moved Permanently"
Response.AddHeader ("Location", "http://www.EXAMPLE.com")
Response.End()
%>
...sometimes the URL you're trying to redirect contains a variable. Try something like this