- Get post custom
- Template Tags/get posts
- List sub categories, and associated posts
- Creating a Filterable WordPress Photo Gallery Using Isotope
/*-------------- Bread Crumb -----*/
function the_breadcrumb() {
global $post;
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> / </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> / </li><li> ');
if (is_single()) {
echo '</li><li class="separator"> / </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li><a href="'.get_permalink($ancestor).'" title="'.get_the_title($ancestor).'">'.get_the_title($ancestor).'</a></li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<li><strong> '.get_the_title().'</strong></li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
<?php the_breadcrumb(); ?> /* call this code in your page*/
------------------ Get content from post ID -------------
<?php $my_postid = 219;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
?>
<h3>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
the_title_attribute(); ?>"><?php echo get_the_title( $my_postid ); ?></a>
</h3>
<p><?php echo get_the_post_thumbnail( $my_postid, 'thumbnail' ); ?></p>
<p class="postdate"> <?php echo $content; ?></p>
------------- List views Looping Code Getting from Category with Posts with content 1 ----------
<div class="row">
<?php $query = new WP_Query( 'cat=0,2' ); ?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 featuredbox wow fadeInDown" data-wow-duration="0.5s">
<div class="featuredicon"> <?php the_post_thumbnail(); ?></div>
<div class="featuredtitle"><a href="<?php echo get_permalink( $post->ID ); ?>" class="btn btn-default btn-custom single"><?php the_title(); ?></a></div>
<p><?php echo the_content(); ?></p>
</div>
<!-- closes the first div box -->
<?php endwhile;
wp_reset_postdata();
else : ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
</div>
------------- List views Looping Code Getting from Category with Posts with content 2 ----------
<?php $query = new WP_Query( 'cat=0,3' ); ?>
// Content limitation function(link)
<?php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-6 col-sm-12">
<div class="servicebox">
<h4> <a href="#" data-toggle="modal" data-target="#<?php the_ID(); ?>"> <span class="titletxt"> <?php the_title(); ?> </span><span class="downloadicon"></span></a> </h4>
<div class="serviceimg"> <a href="#" data-toggle="modal" data-target="#<?php the_ID(); ?>">
<?php the_post_thumbnail(); ?>
</a> </div>
<div class="entry servicetxt"> <a href="<?php echo get_permalink( $post->ID ); ?>" data-toggle="modal" data-target="#<?php the_ID(); ?>"> <?php echo excerpt(80); ?></a> </div>
<div class="servicebox_f">
<div class="dwnld_btn"> <a href="<?php echo get_permalink( $post->ID ); ?>" data-toggle="modal" data-target="#<?php the_ID(); ?>"> <span class="btntxt">Download the Capability Statement</span> </a> </div>
</div>
</div>
</div>
<!-- closes the first div box -->
<?php endwhile;
wp_reset_postdata();
else : ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
/*----- Assign Category and Tags to WordPress Page [ Past in functions page] here link--------*/
function add_taxonomies_to_pages() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'add_taxonomies_to_pages' );
if ( ! is_admin() ) {
add_action( 'pre_get_posts', 'category_and_tag_archives' );
}
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');
if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
$wp_query->set( 'post_type', $my_post_array );
if ( $wp_query->get( 'tag' ) )
$wp_query->set( 'post_type', $my_post_array );
}
------- Post list (links) from Category [ Past in content page]---------
<!-- Category posts starts-->
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 100, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<ul>
<li> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a> </li>
</ul>
<?php }
wp_reset_postdata(); ?>
<!-- Category posts end-->
------- Subcategory Post list (links) in Category ---------
<?php
//get all child categories for category 15, then for each child category display the posts
$parent_cat = 14;
$taxonomy = 'category';
$cat_children = get_term_children( $parent_cat, $taxonomy );
if ($cat_children) {
foreach($cat_children as $category) {
$args=array(
'cat' => $category,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo ' <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 listboxwrap">
<div class="listbox animated fadeInUp">';
echo "<h3>".get_cat_name( $category )."</h3>";
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a></p>
<?php
endwhile;
echo '</div>
</div>';
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
---------- Sub pages with links of Main Parent menu --------------
<?phpglobal $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
} else {
$parent = $wp_query->post->post_parent;
} ?>
<?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?>
<div>
<ul class="bulletlist">
<?php wp_list_pages("title_li=&child_of=$parent" ); ?>
</ul>
</div>
<?php endif; ?>
---------- Get Children of Current Page --------------
<?php$pages = get_pages('child_of='.$post->ID.'&sort_column=post_title');
$count = 0;
foreach($pages as $page)
{ ?>
<div> <?php echo get_the_post_thumbnail( $page->ID ); ?> </div>
<h4><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h4>
<?php
}
?>
---------Custom Pagination Posts with Category -------
Reference Link for paginations click here.
<!-- Start the Loop. -->
<?php
//Protect against arbitrary paged values
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'pagination' => true,
'posts_per_page' => 4,
'category_name' => 'your_catagory_name',
'paged' => $paged,
);
$the_query = new WP_Query( $args ); // call $the_query variable in below loop posts
?>
<!-- Test if the current post is in category Start the Loop. -->
<?php if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="wow fadeInUp">
<!-- <div class="team-member-position"> Founder,President & CEO </div>-->
<div class="contentainer">
<h3 class="title"> <a href="?page_id=<?php the_ID(); ?>">
<?php the_title(); ?>
</a> <span class="date">
<?php the_time(get_option('date_format')); ?>
</span> </h3>
<div class="content"> <?php echo the_content(); ?></div>
</div>
</div>
<?php endwhile; ?>
<?php
wp_reset_postdata();
else : ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
<!-- pagination numeric links here -->
<div class="pagination">
<?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
) );
?>
<!-- pagination numeric links function calling here -->
<?php echo paginate_links( $args ); ?>
</div>
Expiration Date with post in wordpress (link here)
<?php
$currentdate = date("Ymd");
$expirationdate = get_post_custom_values('expiration'); [ expiration is custom field]
if (is_null($expirationdate)) {
$expirestring = '30001212'; //Set future date to posts with expiry.
} else {
if (is_array($expirationdate)) {
$expirestringarray = implode($expirationdate);
}
$expirestring = str_replace("/","",$expirestringarray);
} //else
if ( $expirestring > $currentdate ) { ?>
<!--end expiry code-->
<div class="newsbox">
<?php $exp_date = get_post_meta($post->ID, 'expiration', true); ?>
<p>Expires On : <?php echo $exp_date; ?> </p>
<p>Posted On : <?php echo get_the_date('Y/m/d'); ?> </p>
</div>
<?php } ?>
/*-- category template dynamically---*/
function myCategoryTemplate() {if (is_category() && !is_feed()) {
if (is_category(get_cat_id('projects')) || cat_is_ancestor_of(get_cat_id('projects'), get_query_var('cat'))) {
load_template(TEMPLATEPATH . '/category-projects.php');
exit;
}
}
}
add_action('template_redirect', 'myCategoryTemplate');
/*-- sub category template dynamically---*/
function mySubCategoryTemplate() {if (is_category() && !is_feed()) {
if (is_category(get_cat_id('projects')) || cat_is_ancestor_of(get_cat_id('projects'), get_query_var('cat'))) {
load_template(TEMPLATEPATH . '/category-projects.php');
exit;
}
}
}
add_action('template_redirect', 'mySubCategoryTemplate');
//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Chart', 'taxonomy general name' ),
'singular_name' => _x( 'Chart', 'taxonomy singular name' ),
'search_items' => __( 'Search Topics' ),
'all_items' => __( 'All Topics' ),
'parent_item' => __( 'Parent Topic' ),
'parent_item_colon' => __( 'Parent Topic:' ),
'edit_item' => __( 'Edit Topic' ),
'update_item' => __( 'Update Topic' ),
'add_new_item' => __( 'Add New Topic' ),
'new_item_name' => __( 'New Topic Name' ),
'menu_name' => __( 'Org Chart' ),
);
// Now register the taxonomy
register_taxonomy('topics',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'topic' ),
));
}
//past in your page
<?php
$myterms = get_terms('topics', 'orderby=none&hide_empty');
foreach ($myterms as $term) { ?>
<li><a href="<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li> <?php
} ?>
// past in your page ... All custom taxonomy parent, child list
<?php
/** The taxonomy we want to parse */
$taxonomy = "topics";
/** Get all taxonomy terms */
$terms = get_terms($taxonomy, array(
"orderby" => "count",
"hide_empty" => false
)
);
/** Get terms that have children */
$hierarchy = _get_term_hierarchy($taxonomy);
/** Loop through every term */
foreach($terms as $term) {
//Skip term if it has children
if($term->parent) {
continue;
}
/** Get more children add like this */
if($child->parent) {
continue;
}
?>
<ul id="org" style="display:none">
<li><?php echo $term->name; ?>
<ul>
<?php
/** If the term has children... */
if($hierarchy[$term->term_id]) {
/** display them */
foreach($hierarchy[$term->term_id] as $child) {?>
<li>
<?php
/** Get the term object by its ID */
$child = get_term($child, "topics");
echo $child->name; ?>
<ul>
<?php
/** If the term has children... */
if($hierarchy[$child->term_id]) {
/** display them */
foreach($hierarchy[$child->term_id] as $child2) {?>
<li>
<?php
/** Get the term object by its ID */
$child2 = get_term($child2, "topics");
echo $child2->name; ?>
</li>
<?php }
}
?>
</ul>
</li>
<?php }
}
?>
</ul>
</li>
</ul>
<?php
}
?>
/** The taxonomy we want to parse */
$taxonomy = "topics";
/** Get all taxonomy terms */
$terms = get_terms($taxonomy, array(
"orderby" => "count",
"hide_empty" => false
)
);
/** Get terms that have children */
$hierarchy = _get_term_hierarchy($taxonomy);
/** Loop through every term */
foreach($terms as $term) {
//Skip term if it has children
if($term->parent) {
continue;
}
/** Get more children add like this */
if($child->parent) {
continue;
}
?>
<ul id="org" style="display:none">
<li><?php echo $term->name; ?>
<ul>
<?php
/** If the term has children... */
if($hierarchy[$term->term_id]) {
/** display them */
foreach($hierarchy[$term->term_id] as $child) {?>
<li>
<?php
/** Get the term object by its ID */
$child = get_term($child, "topics");
echo $child->name; ?>
<ul>
<?php
/** If the term has children... */
if($hierarchy[$child->term_id]) {
/** display them */
foreach($hierarchy[$child->term_id] as $child2) {?>
<li>
<?php
/** Get the term object by its ID */
$child2 = get_term($child2, "topics");
echo $child2->name; ?>
</li>
<?php }
}
?>
</ul>
</li>
<?php }
}
?>
</ul>
</li>
</ul>
<?php
}
?>
---------- Custom post type UI-----------------
https://www.youtube.com/watch?v=qpeTZ3ghjtY------------Custom page templates---------------
Creating our own page in wordpres....( Like About us, Services, Contact Us)https://www.youtube.com/watch?v=1TtN-Sz6RHc
https://www.youtube.com/watch?v=9HCxKyj1SV0
------------Create Custom Form---------------
http://www.inkthemes.com/how-you-can-easily-create-customized-form-in-wordpress/
------------ Plugins ---------------
Simple Database Export+Import+Migration
Adminer ( formerly phpMinAdmin)All In One Php ( Executes PHP code on WordPress page)Insert PHP (inserted into WordPress posts and pages)Bootstrap 3 Shortcodes (All Bootstrap elements)Content Views( grid, scrollable list, collapsible list )Custom ScrollbarHuge IT Image Gallery (Image Gallery)Neat Slider (Home Page Slider)WonderPlugin Carousel ( nomber of rows thumbs carousel )Simple File Downloader (Download links into your posts/pages)Visual Form Builder (Dynamically build forms using a simple interface)WordPress Importer ( Import posts, pages, comments, custom fields, categories, tags etc)WP-PageNavi ( Pagination plugin )WR MegaMenu ( Megamenu )Optimus ( Optimisation images)Post Types Order ( Posts in order we can make custom)WP-Mail-SMTP (Reconfigures the wp_mail() function to use SMTP instead of mail)Check and Enable GZIP compression ( checks if you have GZIP compression enabled )BackUpWordPress ( Simple automated backups of your WordPress powered website )Easy URL Shortcodes (EUS) ( urls, paths, and titles using shortcode for easy and consistent website links)MimeTypes Link Icons (Adds icons automatically to any uploads and/or file links inserted into your blog posts.)Page Visit Counter (This plugin will count the total visits of your sites pages.)W3 Total Cache(Easy Web Performance Optimization (WPO) using caching: browser, page, object, database, minify and content delivery network support.)W3 Super Cache(A very fast caching engine for WordPress that produces static html files.)Sitemap – Google XML Sitemap (for SEO)Security – DefenderEmail Integration – WP Mail SMTPSocial Integration/Sharing – Floating SocialBackup – SnapshotSEO – YoastCashing/ Image Compression – HummingbirdBlog Filter – AkismetCarousel/Featured Content – SoliloquyVideo Integration – EnviraSearch Results Enhancement – Rich Snippets