Skip to content

Instantly share code, notes, and snippets.

@jonelvinnaorbe
Last active August 30, 2018 12:18
Show Gist options
  • Save jonelvinnaorbe/e38bf4b4e577f04e5750 to your computer and use it in GitHub Desktop.
Save jonelvinnaorbe/e38bf4b4e577f04e5750 to your computer and use it in GitHub Desktop.
Wordpress Themetation
<?php echo get_option('home'); ?> <!-- get the home URL -->
<?php bloginfo('description'); ?> <!-- display the blog description -->
<?php bloginfo('name'); ?> <!-- display the blog name -->
<?php bloginfo('template_directory') ?> <!-- get the home URL for template's directory -->
<?php echo get_template_directory_uri(); ?>
<?php wp_list_pages('sort_order=desc&title_li='); ?> <!-- display the page list in descending order withour title -->
<?php wp_list_pages('sort_order=desc&depth=1&title_li='); ?> <!-- display the page list in descending order with "current_page_item" class
<?php wp_list_bookmarks(); ?> <!-- display the list of blogrolls -->
<?php echo date('Y'); ?>
==============specific post/page content count==============
<!--put this inside the functions.php-->
<?php if(!function_exists('getPageContent')) {
function getPageContent($pageId,$max_char)
{ if(!is_numeric($pageId))
{return;}
global $wpdb; $nsquery = 'SELECT DISTINCT * FROM ' . $wpdb->posts .' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$post_data = $wpdb->get_results($nsquery);
if(!empty($post_data)){
foreach($post_data as $post)
{ $text_out=nl2br($post->post_content);
$text_out=str_replace(']]>', ']]&gt;', $text_out);
$text_out = strip_tags($text_out);
return substr($text_out,0,$max_char);
}
}
}} ?>
<!-- put this code to your template -->
<?php echo getPageContent(67,150); //First parameter is PAGE ID and second is number of words displayed. ?>
===============show Recent Posts================
<?php
$recent = new WP_Query();
$recent->query('showposts=4');
if($recent->have_posts()) : while($recent->have_posts()): $recent->the_post();
?>
<!--whatever html structure you want to put here to get the_title() the_permalink() and the_excerpt() for each of the members of $recent->the_post()-->
<?php endwhile ?>
<?php else : ?>
<p>Nothing to see here. Move along</p>
<?php endif ?>
<?php echo get_avatar( get_the_author_email(), '80' ); ?>
<?php echo get_avatar($comment, 80); ?>
<?php comment_text(); ?>
===============show title and excerpt of child pages======================
<?php
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<h2 class="subpagetitle"><a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a></h2>
<?php the_excerpt();?>
<?php endforeach; endif; ?>
===============within a loop===============
<?php query_posts('category_name=category1'); ?> <!-- display the posts on specific category -->
<?php the_title(); ?> <!-- display the title of the current post -->
<?php the_content(); ?> <!-- display the contents of the current post -->
<?php the_content(''); ?> <!-- the text "read more" will not show up -->
<?php the_excerpt(); ?> <!-- it will cut the content in specific count and the "read more" will show up after the content -->
<?php the_tags('', ' . ', ''); ?> <!-- dispaly the tags of the post -->
<?php the_time('F jS, Y') ?> <!-- display the time of the current post -->
<?php the_ID(); ?> <!-- display the numeric ID of the current post -->
<?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <!-- display a link to them comment*/
<?php the_author() ?> <!-- display the author's name of the post -->
<?php the_author_ID()?> <!-- display the unique numeric user ID for the author of a post -->
<?php echo get_avatar( $comment, 80 ); ?> <!-- display the commentor avatar in a size of 80px X 80px -->
<?php comment_text() ?> <!-- display the comment content -->
<?php the_permalink() ?> <!-- display the URL for the permalink of the post currently being processed -->
<?php echo get_permalink('$pageID'); ?><!-- get specific page/post link by replacing the '$pageID' with the id number-->
<?php echo get_post_meta($post->ID, 'custom_fields_name', true) ?> <!-- display custom fields on page or posts -->
<!-------- Custom Fields with Default Value ------------->
<?php if(get_post_meta($post->ID, 'custom_fields_name', true)){ $custom_fields_name = get_post_meta($post->ID, 'custom_fields_name', true); }else{ $custom_fields_name = "Default Value"; } ?>
<img src="<?php echo $custom_fields_name; ?>" alt="" />
<!-------- Custom Fields with Default Value ------------->
<?php echo get_the_post_thumbnail('$pageID');?> <!-- get specific post featured image by replacing the '$pageID' with the id number-->
<?php comment_form(); ?>
============Pagenavigation===============
<?php previous_post_link('%link', 'Previous Post') ?> <!-- display a link to the previous post with an anchor text as "Previous Post" -->
<?php next_post_link('%link', 'Next Post') ?> <!-- display a link to the next post with an anchor text as "Next Post" -->
<?php posts_nav_link('','','« Previous Entries') ?> <!-- display a link to the previous page with an anchor text as "Previous Page" -->
<?php posts_nav_link('','Next Entries »','') ?> <!-- display a link to the next page with an anchor text as "Next Page" -->
<?php previous_image_link() ?> <!-- display a link to the previous image within the gallery -->
<?php next_image_link() ?> <!-- display a link to the previous image within the gallery -->
============file linking=================
<?php get_header(); ?> <!-- load header.php -->
<?php get_sidebar(); ?> <!-- load sidebar.php -->
<?php get_footer(); ?> <!-- load footer.php -->
<?php comments_template(); ?> <!-- load comments.php -->
<?php include (TEMPLATEPATH . '/searchform.php'); ?> <!-- load searchform.php -->
<?php include('about.php'); ?> <!-- load about.php -->
<?php include('featured-post.php'); ?><!-- load featured-post.php -->
<?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
============widgetize sidebar============
<?php
function twentyeleven_widgets_init() {
// Add this block of codes to add widget container
register_sidebar( array(
'name' => __( 'Main Sidebar', 'twentyeleven' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="sidewidget-title">',
'after_title' => '</h3>',
) );
}
?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-1') ) : ?>
<?php endif; ?>
============define the page template name in admin panel==================
<?php
/*
Template Name: Links
*/
?>
============display child pages of the current parent page==================
<h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?></h2>
<?php
if ($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
============normal post loop==================
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- a normal posts loop, the contents go here -->
<?php endwhile; else: ?>
<?php endif; ?><!-- end loop -->
============secondary post loop==================
<?php global $post; $myposts = get_posts('category_name=portfolio&showposts=6'); foreach($myposts as $post) : setup_postdata($post); ?>
<!-- a secondary posts loop, the contents go here -- >
<?php endforeach; ?>
<?php $the_slug = 'we-can-handle-customer'; global $post; $myposts = get_posts($args=array('name' => $the_slug)); foreach($myposts as $post) : setup_postdata($post); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content"><?php the_content(); ?></div>
<?php endforeach; ?>
============get posts from category name==================
<?php query_posts('category_name=cat_name&showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<p><?php echo substr(get_the_content(), 0,450)."[...]"; ?></p>
<a href="<?php the_permalink(); ?>">Read More</a>
<?php endwhile; ?>
====================menu system======================
<?php
if (function_exists('add_theme_support')) {
add_theme_support('menus');
}
?>
============query post loop==================
<?php query_posts($query_string);
while (have_posts()) : the_post(); ?> <!-- get all posts excluding posts under category with ID=3 -->
<!-- the contents go here -->
<?php endwhile; ?><!-- end loop -->
=================homepage===================
<?php if(is_front_page()) { ?>
<!-- <put here your code that you want to appear in homepage> -->
<?php } ?>
<!--OR-->
<?php if( is_home() || is_front_page()) { ?>
<!-- <put here your code that you want to appear in homepage> -->
<?php } ?>
=================if specific page is viewed===================
<?php if(is_page($page)) { ?>
<!-- <put here your code that you want to appear in specific page> -->
<?php } ?>
============get Category Link (by name)============
<?php
// Get the ID of a given category
$category_id = get_cat_ID( 'Category Name' );
// Get the URL of this category
$category_link = get_category_link( $category_id );
?>
<!-- Print a link to this category -->
<a href="<?php echo $category_link; ?>" title="Category Name">Category Name</a>
============comment loop==================
<?php foreach ($comments as $comment) : ?> <!-- start the comments loop -->
<?php endforeach; ?><!-- end comments loop -->
============use of custom fields==================
<?php while (have_posts()) : the_post(); //start the loop
$myphoto = get_post_meta($post->ID, "myphoto", TRUE); //define the custom field key for the post being processed in the loop with the ID
$mydesc = get_post_meta($post->ID, "mydesc", TRUE); //define the custom field key for the post being processed in the loop with the ID
?>
<?php echo $mydesc; ?> <!-- display the custom field value -->
<?php endwhile; ?> <!-- end loop -->
=============== shortcodes ==================
<?php echo do_shortcode("[contact-form 1 'Contact form 1']"); ?> <!-- Contact Form php code -->
marketing_icons_left <!-- display items on menu system -->
<?php wp_nav_menu('menu=mainmenu'); ?>
<?php if (function_exists('easing_slider')){ easing_slider(); }; ?> <!-- easing slider shortcodes -->
<?php the_post_thumbnail('featured-image');?> <!-- display the Featured Image of specific Page/Post -->
<!-----------------get featured image url ---------------->
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" />
<?php endif;?>
<!----- end ------>
=============== Cross Browser Opacity ==================
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; filter: alpha(opacity=50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.5;
=============== The Excerpt ==================
<?php echo substr(get_the_excerpt(), 0,125); ?>
=============== Condition by Page Template ==================
<?php if ( is_page_template('page-templates/inner-page-red.php') ) { ?>
<?php } ?>
=============== Creating Shortcode ==================
function lorem($atts){
extract(shortcode_atts(array( 'width' => null, 'height' => null, 'cat' => "people" ), $atts));
return '<img src="http://lorempixel.com/'. $width . '/'. $height . '/'.$cat.'" />';
}
add_shortcode('lo70r em','lorem');
=============== Insert an element on IE ==================
*zoom: expression( this.runtimeStyle.zoom="1",this.appendChild( document.createElement("small") ).className="after");
=============== Grayscale ==================
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */filter: gray; /* IE6-9 */-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
=============== Display Child pages of the current parent page ==================
<h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?></h2>
<?php
if ($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul><?php echo $children; ?></ul>
<?php } ?>
=============== Clearfix ==================
.clearfix { *zoom: 1;}
.clearfix:before, .clearfix:after { display: table; line-height: 0; content: "";}
.clearfix:after { clear: both;}
=============== Canvas Theme ==================
Contact us by leaving a voice mail message on the number below, sending an email or by simply completing the contact form below and we will soon by in touch to see how we can help.
<?php $geocoords = $woo_options['woo_contactform_map_coords']; ?>
<?php if ($geocoords != '') { ?>
<?php woo_maps_contact_output("geocoords=$geocoords"); ?>
<?php echo do_shortcode( '[hr]' ); ?>
<?php } ?>
<?php $geocoords = $woo_options['woo_contactform_map_coords']; ?>
<?php if ($geocoords != '') { ?>
<?php woo_maps_contact_output("geocoords=$geocoords"); ?>
<?php echo do_shortcode( '[hr]' ); ?>
<?php } ?>
=============== Plugins ==================
/**
* Creates sharethis shortcode
*/
if (function_exists('st_makeEntries')) :
add_shortcode('sharethis', 'st_makeEntries');
endif;
@media screen and (min-width:0\0) { }
wp_login_url() and wp_logout_url()
{block:HasPages}
<ul>
<li><a href="/">Home</a></li>
{block:Pages}<li><a href="{URL}">{Label}</a></li>{/block:Pages}
</ul>
{/block:HasPages}
<ul class="socmed">
<li><a href="#" class="facebook"></a></li>
<li><a href="#" class="twitter"></a></li>
<li><a href="#" class="youtube"></a></li>
<li><a href="#" class="rss"></a></li>
</ul>
<style type="text/css">
ul.socmed{list-style: none; margin: 0; padding: 0;}
ul.socmed li{display: inline-block; *display: inline; *zoom: 1; margin: 0 10px;}
ul.socmed li a{display: block; background: url(images/socmed.png) no-repeat 0 0; width: 20px; height: 20px;}
ul.socmed li a.facebook{background-position: 0 0;}
ul.socmed li a.facebook:hover{background-position: 0 0;}
ul.socmed li a.twitter{background-position: 0 0;}
ul.socmed li a.twitter:hover{background-position: 0 0;}
ul.socmed li a.youtube{background-position: 0 0;}
ul.socmed li a.youtube:hover{background-position: 0 0;}
ul.socmed li a.rss{background-position: 0 0;}
ul.socmed li a.rss:hover{background-position: 0 0;}
</style>
/*** ACF ***/
<?php if(get_field('page_layout') == "col_1"){} ?>
<?php $posts = get_field('relationship');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
/**** WP QUERY ******************/
<div class="remodelling_seminars">
<h3>Remodelling Seminar Event Dates</h3>
<?php
// The Query
$the_query = new WP_Query('post_type=seminar');
// The Loop
if ( $the_query->have_posts() ) {
?>
<ul class="bullet_list">
<?php
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
<?php
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
</div>
<?php
// The Query
$args = array(
'post_type' => 'cust_before_after',
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<div>content here</div>
<?php
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
/**** QUERY FROM YEAR ******************/
<?php
$loc_query = new WP_Query( array(
'post_type' => 'press_release',
'date_query' => array(
array(
'after' => $after_query, //from January 1
'before' => array(
'year' => $next_year,
'month' => 1,
'day' => 1,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
) );
?>
<?php } } else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
/**** IF PAGE HAS PARENT ******************/
<?php
if ( is_page() && $post->post_parent ){
$press_id = $post->post_parent;
} else {
$press_id = get_the_ID();
}
?>
/**** IF PAGE HAS CHILD ******************/
<?php
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);
}
?>
/**** Databse query ******************/
<?php
$fivesdrafts = $wpdb->get_results(
"
SELECT ID, post_title
FROM $wpdb->posts
"
);
?>
<?php
foreach ( $fivesdrafts as $fivesdraft )
{
echo $fivesdraft->post_title;
}
?>
/**** Element Loader ******************/
$("#myImage").attr("src","img/spinner.gif");
var img = new Image();
$(img).load(function() {
$("#myImage").attr("src",img.src);
});
img.src = "http://example.com/imageToPreload.jpg";
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 10,
'paged' => $paged,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<?php } } else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
?>
//draggable
(function($) {
$.fn.drags = function(opt) {
opt = $.extend({handle:"",cursor:"move"}, opt);
if(opt.handle === "") {
var $el = this;
} else {
var $el = this.find(opt.handle);
}
return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
if(opt.handle === "") {
var $drag = $(this).addClass('draggable');
} else {
var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
}
var z_idx = $drag.css('z-index'),
drg_h = $drag.outerHeight(),
drg_w = $drag.outerWidth(),
pos_y = $drag.offset().top + drg_h - e.pageY,
pos_x = $drag.offset().left + drg_w - e.pageX;
$drag.css('z-index', 1000).parents().on("mousemove", function(e) {
$('.draggable').offset({
top:e.pageY + pos_y - drg_h,
left:e.pageX + pos_x - drg_w
}).on("mouseup", function() {
$(this).removeClass('draggable').css('z-index', z_idx);
});
});
e.preventDefault(); // disable selection
}).on("mouseup", function() {
if(opt.handle === "") {
$(this).removeClass('draggable');
} else {
$(this).removeClass('active-handle').parent().removeClass('draggable');
}
});
}
})(jQuery);
.col mobile_12_of_12{}
/*Responsive*/
@media (max-width: 767px){}
@media (min-width: 768px) and (max-width: 991px){}
@media (max-width: 991px){
.mb-10, .mb-20, .mb-30, .mb-40, .mb-50, .mb-60, .mb-70, .mb-80, .mb-90, .mb-100{margin-bottom: 15px;}
}
@media (min-width: 992px){}
$('.app-top-menu .menu li').click(function(){
var fruit = "Hello world";
jQuery.ajax({
url: "ajax.php",
type : 'post',
data: {
'fruit' : fruit
},
beforeSend: function(){
//jQuery(".content-here").html('loading');
},
success: function(data){
jQuery('.app-top').html(data);
//alert(data);
}
});
});
<?php
if( have_rows('repeater_field_name') ):
while ( have_rows('repeater_field_name') ) : the_row();
div
?>
< class="cust-gallery-item">
<?php the_sub_field('sub_field_name'); ?>
</div>
<?php
endwhile;
else :
// no rows found
endif;
?>
<?php
///////exclude categories from blog page(add to functions.php)
function exclude_category($query) {
if ( $query->is_home() ) {
//$query->set('cat', '-24 -23');
$query->set('cat', '-21 -22 -23 -24');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
?>
http://12devs.co.uk/articles/handy-advanced-sass/
@mrniceguy001
Copy link

Idol salamat pala dito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment