• i wanna make a php code on my posts. my posts using <!–nextpage–> tag.
    thing is, i wanna show this code only in the “page 1” of my posts.

    Is there a way to do it?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • anonymized-13749270

    (@anonymized-13749270)

    thing is, i wanna show this code only in the “page 1” of my posts.

    How is pagination slug working for your posts?

    1. site.com/hello-world/page/1/

    $url = $_SERVER["REQUEST_URI"]/* or get_the_permalink() for single posts*/;
    if(strpos($url,"page/") != '' && strpos($url,"page/1" ) != '')
    	echo "Let's do it!";

    2. site.com/hello-world?page=1

    if(!isset($_GET["page"]) || isset($_GET["page"]) && $_GET["page"] == "1")
    	echo "Let's do it!";
    Thread Starter valtmedia

    (@valtmedia)

    thanks, but its: 1. site.com/hello-world/1/

    anonymized-13749270

    (@anonymized-13749270)

    Oh. then maybe this would work:

    global $post;
    $url = $_SERVER["REQUEST_URI"]/* or get_the_permalink() for single posts*/;
    if($url == home_url( '/' ).$post->post_name || strpos($url,$post->post_name."/1" ) != '')
    	echo "Let's do it!"; // do something here, condition: request uri is site.com/hello-world/ or  site.com/hello-world/1/ only, so site.com/hello-world/2/ and other pages are eliminated

    Let me know how it goes.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘show code only in part 1’ is closed to new replies.