0

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

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you so much for your answer it works fine for number 2,3,4. but for the <span class="current">1</span> it's not changed, it is should be<span class="current">១</span>, it is the current page we stay in page 1.And sometime can stay current in other page 2 or 3 or 4 or...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.