Skip to content

Instantly share code, notes, and snippets.

View vajrasar's full-sized avatar

Vajrasar Goswami vajrasar

View GitHub Profile
@vajrasar
vajrasar / functions.php
Created April 23, 2013 10:13
Modifying Genesis author box on archive template. Showing author box only when archive is of 'blog' category. Code goes in functions.php
remove_action( 'genesis_before_loop', 'genesis_do_author_box_archive' );
add_action( 'genesis_before_loop', 'theme_author_box_archive' );
function theme_author_box_archive() {
$authinfo = "<div class=\"author-box\">\r\n";
$authinfo .= get_avatar( get_the_author_meta('email', (int) get_query_var( 'author' )), '50' );
$authinfo .= "<b>" . get_the_author_meta('display_name', (int) get_query_var( 'author' )) . "\n </b>";
$authinfo .= "<p>" . get_the_author_meta('description', (int) get_query_var( 'author' )) . "</p>\r\n";
$facebook = get_the_author_meta('facebook_profile', (int) get_query_var( 'author' ));
$twitter = get_the_author_meta('twitter_profile', (int) get_query_var( 'author' ));
@vajrasar
vajrasar / local-plugin-cpt.php
Created June 13, 2013 11:31
This is how I achieved following URL pattern while using the custom post type and custom taxonomy associated with it. - CPT Archive - xyz.com/classifieds - Custom Taxonomy - xyz.com/classifieds/automobiles - Single Post - xyz.com/classifieds/automobiles/Sell-My-Benz
<?php
/****Creating Custom Post Types of Classifieds Starts****/
function my_custom_post_classifieds() {
$labels = array(
'name' => _x( 'Classifieds', 'post type general name' ),
'singular_name' => _x( 'Classified', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Classified' ),
@vajrasar
vajrasar / sidebar-stuff.php
Created June 24, 2013 18:02
to engage sidebar-content-sidebar layout in Genesis.
<?php
/*
The below written code went into functions.php
*/
genesis_register_sidebar( array(
'id' => 'wishes-sidebar',
'name' => 'wishes Sidebar',
'description' => 'This is wishes Sidebar.',
) );
@vajrasar
vajrasar / divtest.html
Last active December 21, 2015 05:28
html issue
<html>
<head>
<style>
#maincont {
border: 1px solid black;
width: 910px;
overflow: hidden;
min-height: 400px;
margin: 0 auto;
}
@vajrasar
vajrasar / image-above-title.php
Created September 14, 2013 07:11
This code gets the first image of the post (not the featured image) and places it above the Post Title and in second step it removes the first-image-of-content (the_content) from post content to remove same image showing twice (above title and in content). Code goes in functions.php
<?php
add_action('genesis_entry_header','image_above_t',7);
function image_above_t() {
?>
<div id="i_a_t" style="width: 200px; margin:0 auto;">
<?php
echo genesis_get_image();
?>
</div>
@vajrasar
vajrasar / fetch_tweet_and_likes.php
Last active December 23, 2015 01:38
This snippet fetches number of Facebook Likes and Tweets for a post (wordpress). It can be done via 1000s of plugins available, but via this snippet we get full control over presentation.
<?php
function getShares($atts) {
extract(shortcode_atts(array(
'url' => '',
'p_id' => '',
'bordercolor' => '#dddddd',
'textcolor' => '#333333',
'border ' => '1',
'bordertype' => 'solid',
@vajrasar
vajrasar / image-above-title-2.php
Last active December 23, 2015 11:18
This code gets the first image of the post (not the featured image) and places it above the Post Title and in second step it removes the first-image-of-content (the_content) from post content to remove same image showing twice (above title and in content). Code goes in functions.php
<?php
//to catch & print first image occuring in post content (the_content) via famous 'catch-that-image'
/* we could have also used genesis_get_image() to catch the first image instead of 'catch_that_image' script;
but genesis_get_image() was actually catching "first uploaded image" instead of "first image occuring in the_content".
Link to snippet using genesis_get_image -- https://gist.github.com/vajrasar/6559551
*/
######################
#Script1 : scraper.py
######################
import urllib2
import datetime
def main():
ph = urllib2.ProxyHandler({'http': 'http://xxx:xxxx@netmon.iitb.ac.in:80'})
opener = urllib2.build_opener(ph)
@vajrasar
vajrasar / add_jetpack_infinite.php
Last active July 13, 2017 19:57 — forked from anonymous/add_jetpack_infinite.php
Steps to add Infinite Scroll (Jetpack) to a Genesis Child Theme running on Genesis 2.0 + HTML 5. Code goes in functions.php
<?php
/*
To add Infinite Loop Module provided in Jetpack wordpress Plugin, in Genesis driven site.
*/
/*
Step 1. Install Jetpack Plugin
*/
@vajrasar
vajrasar / find_first_image_width.php
Created September 27, 2013 10:36
Scenario: You 'only' have 'url' of first image occurring in your 'the_content' and you want to find that image's width/height. Code goes in functions.php
<?php
/*
Here we will find out the WIDTH of 'first' image occuring in our 'the_content'
*/
/*
Step: 1
Using the famous 'catch_that_image' snippet, we will fetch the url of first image
occuring in the content and will pass the same url while calling a function to find