admin

Website Tutorial

WordPress-How to create a Taxonomy?

Here is an example of registering a “people” taxonomy function people_init() { // create a new taxonomy register_taxonomy ( 'people', 'post', array( 'label' => _('people'), 'rewrite' => array('slug' => 'person'), 'capabilities' => array( 'assign_terms' => 'edit_guides', 'edit_terms' => 'publish_guides', )...
Website Tutorial

WordPress display articles by category

<?php $cat_query = new WP_Query(array( 'cat' => '2' )); ?> <div id="sitebar"> <ul class="nav nav-pills nav-stacked nav-og"> <?php if ($cat_query->have_posts()) : while ($cat_query->have_posts()) : $cat_query->the_post(); ?> <li><a href=“<?php the_permalink() ?>” target=“_blank” title=“<?php the_title(); ?>”><?php the_title(); ?></a></li> <?php endwhile; ?> <?php...
Website Tutorial

How to Display Total Views on WordPress Posts

How to Display Total Views on WordPress Posts Place the code in your functions.php file function getPostViews($postID){getPostViews(get_the_ID()); $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } function...
Website Tutorial

WordPress-How to list custom post-type?

Listing custom post types in WordPress involves a few steps, but it’s relatively straightforward. Here’s a general guide to help you get started: 1. Register Your Custom Post Type First, make sure you have a custom post type registered. You...
Website Tutorial

WordPress-How to show single post content in front-end?

WordPress-How to show single post content in front-end? <?php if(have_posts()) : while (have_posts()) : the_post(); the_title(); echo ‘<div class=”entry-content”>’; the_content(); if(get_post_meta($post->ID, ‘key-name’, true)){ echo get_post_meta($post->ID, ‘key-name’, true); } echo ‘</div>’; endwhile; endif; ?>
Website Tutorial

WordPress Gravatar avatar cached locally

In order to improve the user experience, I thought of caching the commenter’s avatar locally. Most of the avatar files are in png format. I tried to delete all cached avatars and re-cache them. After refreshing, the avatars can be...
Website Tutorial

Get all WordPress category names and IDs

function show_category(){ global $wpdb; $request = “SELECT $wpdb->terms.term_id, name FROM $wpdb->terms “; $request .= ” LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id “; $request .= ” WHERE $wpdb->term_taxonomy.taxonomy = ‘category’ “; $request .= ” ORDER BY term_id asc”; $categorys =...