Friday, January 24, 2014

Step by step instructions to Create Custom Wordpress Template Tags.

Advertisements
Building a Wordpress topic is so natural with model tags. You can include the_title() to show the post or page title, and you can utilize the_content() to show post or page substance. There are a lot of people more pattern tags in Wordpress that we can use to show different things. 


Yet in terms of showing just specific things on your subject, you may need to make your own particular pattern tag. In today's excercise, we are set to walk you through this not-excessively muddled procedure. Wouldn't it be great if we could begin with the essentials.

Recommended Posts : 

 

Template Tag for Page View Count 




To begin with, introduce and initiate Wordpress.com Stat in Jetpack. Also verify that you have joined Jetpack to Wordpress.com. The explanation for why we utilize Wordpress.com Stat is that the View information will be archived in Wordpress.com instead of in our own particular database. This could spare on our server load.


  • Make a capacity in your functions.php  and name it as the_view()


function the_view() {
}   
          

  • We will put the capacity (the pattern tag) in a page or post, so we have to get the page and post ID number. This could be recovered utilizing get_the_ID();


function the_view() {
                $id = get_the_ID();
}    
         

  • We can use a function to retrieve the number of views in WordPress.com Stats by using stats_get_csv();.
  • In this case, we should to add the days, which mention the time range of the view count, and that post_id.


function the_view() {
                $id = get_the_ID();
                $page_view = stats_get_csv('postviews', 'days=-1&post_id='.$id.'');
}


  • In the code above, since we set the days parameter to -1, we will recover the perspective check of the given post ID from the precise starting, from when the Wordpress.com Stat plugin is initiated.

When we've the number, we recently need to reverberate it, as takes after. 


function the_view() {
                $id = get_the_ID();
                $page_view = stats_get_csv('postviews', 'days=-1&post_id='.$id.'');
                echo $page_view[0]['views'];
}
 


  • That is it, our new model tag for showing site visit tally is carried out. You can <?php the_view() ;?>   in single.php page or anywhere in page.php.

When you have any inquiries, please don't hesitate to place them in the remark segment beneath.
Like the Post? Share with your Friends:-

0 comments:

We're excited to see your comments. Be that as it may, Please Keep at the top of the priority list that all Comments are directed physically by our human commentators as per our Comment Policies,and all the connections are no follow. Note:1. Please do not spam Utilizing Keywords within the name field territory is prohibited. We should appreciate a particular and reminiscent discussion
comments powered by Disqus