• Resolved craigmedia

    (@craigmedia)


    Hello,
    I’ve been trying to figure something out, I usually use is_page() but I notice it doesn’t work in the loop. I have a website that’s displaying all pages content on the home page as I want my site to be a One page site with smooth scrolling.

    Cool now the issue is. I have a hidden content in the loop where I only want it to display just under the About Page. I usually use is_page(‘5’) but it doesn’t work in the loop. Is there another method similar to is_page() where I can say:

    “If page_id = 5 then display this hidden content endif.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Generally the loop is used to display posts, on a specific page. Are you using the loop to display page content instead of post content?

    Anyway, in the loop, use

    get_the_ID()

    to get the current post id.

    Thread Starter craigmedia

    (@craigmedia)

    Hey Scriptrunner,
    Thanks for the prompt reply. I’m using a custom loop I found online that enables me to display all content on one page. I’ve posted it here on Pastebin http://pastebin.com/f3x8L8Yi.

    So where it says:

    <!–THIS IS WHERE I WANT THE CODE TO APPEAR BUT ONLY AFTER PAGE ID 5–>
    <!–THIS IS WHERE I WANT THE CODE TO APPEAR BUT ONLY AFTER PAGE ID 5 ENDS–>

    in the pastebin, I wanted that the is_page() to go there so that it will say that if the page id is 5 then display this hidden content. I normally use is_page but that doesn’t work in the loop. You have any idea or know if there’s a alternative solution for is_page() that can be used in the loop?

    Thanks

    $page_data->ID;
    Thread Starter craigmedia

    (@craigmedia)

    Hey Script,
    So that identifies the ID. How would I or what would I use in the code to say.

    If this is page-id = 5 display this
    Content
    End IF

    Thanks

    Untested, but you should be able to do this:

    if ( 5 == $page_data->ID ) {
        // Do your stuff here
    }
    Thread Starter craigmedia

    (@craigmedia)

    Soooo Cool.

    Thanks heaps for that 🙂 WORKED GREAT.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘is_page not to use in loop, alternaltive for it???’ is closed to new replies.