Skip to content

Instantly share code, notes, and snippets.

View developer-anuragsingh's full-sized avatar

Anurag Singh developer-anuragsingh

  • Cendyn
  • Gurugram
View GitHub Profile
@developer-anuragsingh
developer-anuragsingh / Make a pyramid with asterisk (*) in PHP
Last active August 29, 2015 14:24
Simple PHP program for beginners
<?php
$height = 3;
$extraStar = 1;
for($i=1; $i<=$height; $i++){
for($j=$i; $j<=$height-1; $j++){
echo "&nbsp;";
}
for($k=1; $k<=$i; $k++){
echo "*";
@developer-anuragsingh
developer-anuragsingh / Find all Prime numbers in a given range through PHP
Created July 4, 2015 13:22
Find all the Prime numbers with the PHP function
<?php
function find_prime_nums($start, $end){
for($i=$start; $i<=$end; $i++){
$counter = 0;
for($j=1; $j<=$i; $j++){
if($i%$j == 0){
$counter++;
}
@developer-anuragsingh
developer-anuragsingh / css_resources.md
Last active August 29, 2015 14:24 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@developer-anuragsingh
developer-anuragsingh / javascript_resources.md
Last active August 29, 2015 14:24 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@developer-anuragsingh
developer-anuragsingh / WordPress posts from a single category
Last active August 29, 2015 14:25
Display wordpress posts only from a particular category
<?php
$cat_name = 'Abc'; # Set the category name
$args = array ( # Define Arguments want to supply
'category_name' => $cat_name,
'posts_per_page' => 2,
);
$query = new WP_Query($args); # Object initialization of WP_query
function create_cpt($cpt_name) {
$cpt_name = ucwords(strtolower(preg_replace('/\s+/', ' ', $cpt_name) ));
$single = ucfirst($cpt_name);
$textdomain = strtolower(str_replace(" ", "_", $single)); // Sanitize slug
$cap_type = 'post';
$last_character = substr($single, -1);
if ($last_character === 'y') {
$plural = substr_replace($single, 'ies', -1);
<?php $myMetaFields = get_post_meta($post->ID, 'YOUR_META_KEY', true);
foreach($myMetaFields as $singleFiled) {
$attachmentId = $singleFiled['icon'];
$attachmentUrl = wp_get_attachment_image_src( $attachmentId, 'full' );
$src = $attachmentUrl[0];
$attachmentMetaData = wp_get_attachment_metadata($attachmentId);
$attachmentWidth = $attachmentMetaData['width'];
<?php
// Display all images directly from post meta field
$postMeta = get_post_meta($post->ID, 'YOUR_META_KEY');
foreach ($postMeta as $attachmentId) {
echo wp_get_attachment_image( $attachmentId, 'large', "", array( "class" => "img-fluid" ) );
}
?>
<?php
//Get the custom taxonomy term 'name' and 'description'
$taxonomy = 'YOUR_CUSTOM_TAXO_NAME';
$terms = wp_get_object_terms( $post->ID, $taxonomy, array('orderby'=>'term_order') );
if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
$taxoID = $terms[1]->term_id;
#var_dump($terms);
$customTaxoName = $terms[1]->name;
$customTaxoDescription = term_description( $taxoID, 'YOUR_CUSTOM_TAXO_NAME' );