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’, ) ) ); } add_action(‘init’, ‘people_init’); Here is an example of adding the term John to…
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 endif; ?> </ul> </div>
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 setPostViews($postID) {setPostViews(get_the_ID()); $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count = 0; delete_post_meta($postID,…
Website Tutorial How to enable two-factor authentication on your WordPress website
Enabling two-factor authentication (2FA) on your WordPress website adds an extra layer of security by requiring a second form of verification beyond just a password. Here’s a step-by-step guide to set it up: Using a Plugin The easiest way to enable 2FA is by using a WordPress plugin. Here’s how: Log in to your WordPress…
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 can register a custom post type by adding code to your theme’s functions.php file or…
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 displayed normally. The following is the cached avatar code: function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt)…
Website Tutorial the Difference Between `localhost` and `127.0.0.1` IP Addresses
localhost is a hostname that refers to the current computer or device that you are using. It is commonly used to access web applications or server software that is running on the same machine. When you use the localhost hostname in a web browser or other networked application, it resolves to the IP address 127.0.0.1. 127.0.0.1 is a loopback IP…
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 = $wpdb->get_results($request); foreach ($categorys as $category) { $output = ‘<span>’.$category->name.”(<em>”.$category->term_id.'</em>)</span>’; echo $output; } }