WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_page not to use in loop, alternaltive for it??? (7 posts)

  1. craigmedia
    Member
    Posted 10 months ago #

    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.

  2. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    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.

  3. craigmedia
    Member
    Posted 10 months ago #

    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

  4. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    $page_data->ID;
  5. craigmedia
    Member
    Posted 10 months ago #

    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

  6. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    Untested, but you should be able to do this:

    if ( 5 == $page_data->ID ) {
        // Do your stuff here
    }
  7. craigmedia
    Member
    Posted 10 months ago #

    Soooo Cool.

    Thanks heaps for that :) WORKED GREAT.

Reply

You must log in to post.

About this Topic