Maly
Maly

Reputation: 3

Change the pagination number using jquery, javascript,wordpress

I have the wordpress website that use the pagination and I'm also use the plugin Pagenavi for pagination but I can not use it as my language number so I need to customize code by using jquery and javascript. I have the code as below :

<div class="wp-pagenavi">
<span class="pages">ទំព័រ 1​ នៃទំព័រ 4</span>
<span class="current">1</span>
<a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/2/">2</a>
<a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/3/">3</a>
<a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/4/">4</a>
<a class="nextpostslink" href="http://192.168.1.136:85/pic/publications/research-documents/page/2/">»</a>

I want to change the number of 1,2,3,4,....in <a> value to the khmer number such as ១​,២,៣, ៤... I have try some code but it is not success as below:

var getPagination = $("div.wp-pagenavi a.larger").length;
var findcurrent = $("div.wp-pagenavi span.current").text();
var page = '';
for(i =1;i<= getPagination;i++){            
        page = $( "div.wp-pagenavi a.larger:nth-of-type("+i+")" ).text();
        switch(i){
            case 1:
                numgl =  "១";
                break;
            case 2:
                numgl = "២";

                break;
            case 3:
                numgl = "៣";                    
                break;
            case 4:
                numgl = "៤";                    
                break;

        }
           //if it current pagination
           $("div.wp-pagenavi span.current").text(numgl);
           //for other number of pagination
           $( "div.wp-pagenavi a.larger:nth-of-type("+i+")" ).text(function( i) {   
                return numgl;           

            });

}

I have tried it but it not work.Anyone know help me please, thanks

Upvotes: 0

Views: 670

Answers (1)

Eyal
Eyal

Reputation: 788

The below snippet will replace the numbers 2,3,4 with their equivalents. You can use a variation of this code to replace it everywhere you want.

var replacementArray = ['១', '២', '៣', '៤']
var $pager = $('.wp-pagenavi');
$pager.children('a').each(function() {
  var $this = $(this);
  var int = parseInt($this.text());
  $this.text(replacementArray[int - 1]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wp-pagenavi">
  <span class="pages">ទំព័រ 1​ នៃទំព័រ 4</span>
  <span class="current">1</span>
  <a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/2/">2</a>
  <a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/3/">3</a>
  <a class="page larger" href="http://192.168.1.136:85/pic/publications/research-documents/page/4/">4</a>
  <a class="nextpostslink" href="http://192.168.1.136:85/pic/publications/research-documents/page/2/">»</a>
</div>

Upvotes: 1

Related Questions