Page 1 of 1

How can I get the PageID ?

Posted: 21 Jan 2017, 23:26
by lenstudio
Hi~~ Just want to know is there a GetPageID function for the custom script use for locate the page?

eg.  <script src="http://aaa.com/api.js?id=<?=$PageID?>"></script>

So I can use the script at [Custom Javascript] section for the pages

Many thanks for your help :)

Re: How can I get the PageID ?

Posted: 22 Jan 2017, 05:34
by mjau-mjau
What ID are you looking for? What will you use it for? You mean to get CURRENT page name or something?

Re: How can I get the PageID ?

Posted: 22 Jan 2017, 20:32
by lenstudio
I just want to use a function like Disqus , ( Cause Disqus had been blocked in China :( ), So I found another services in China, but the function needs a PageID to distinguish the message. 

eg. if use with wordpress template:
Code
<div id="SOHUCS" sid="<?php the_ID(); ?>" ></div>
<script charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/changyan.js" ></script>
<script type="text/javascript">
window.changyan.api.config({
appid: 'cysO2W0K1',
conf: 'prod_8952fb94728347ccdc0f79b420cf6f95'
});
</script>

the_ID()  should be the current page id.

So is there any function to get it ?

Here is the FAQ: 
https://translate.google.com/translate? ... edit-text=

Thank you so much !

Re: How can I get the PageID ?

Posted: 22 Jan 2017, 23:14
by mjau-mjau
From javascript, you should be able to use:
Code
x3_settings.id
You need to be cautious about when you trigger your custom script though. The ID is only available after page is loaded (bottom of page), and what about when you navigate to the page from the nav (Ajax)? You should really be using the x3_page_load() event function (settings -> custom - > custom JS) to trigger your script. Let me know if you need any help.

Re: How can I get the PageID ?

Posted: 23 Jan 2017, 08:52
by lenstudio
:thumbsup: :thumbsup: :thumbsup: :thumbsup:  Thank you so much! 
Code
function x3_load_page(){
document.getElementById("bqs").innerHTML='<div id="SOHUCS" sid="'+x3_settings.id+'"></div>';
window.changyan.api.config({
appid: 'cysO2W0K1',
conf: 'prod_8952fb94728347ccdc0f79b420cf6f95'
});
}
It works!! 

Re: How can I get the PageID ?

Posted: 23 Jan 2017, 10:45
by mjau-mjau
Nice!  :star: :punch: :star: