• Is there a way to get a post’s ID number w/o it being printed out? I tried the following:

    <?php if (the_ID() == 2) echo “test”; ?>

    and it printed out the ID number instead of ‘test’

    I don’t see any other template tags that are applicable. Is there an easy way to pull it from the database?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m not an expert on this, but isn’t the whole point of the tag to get the ID number as a result and it sounds like you are trying to overwrite that function to make it result in “test”. I think there must be a better way to do this….

    Yeah, what do you want the number for anyway then? Maybe if we knew what the goal was, then we could figure something out.

    Thread Starter dirvish

    (@dirvish)

    I was trying to have an ad displayed after every fourth blog post (“test” would have been replaced w/ the ad code), I was going to use gmp_mod with the post id number, but I f0und an easier way to do it:

    <?
    if ($my_id == 0)
    {
    echo “<br><br><div align=center>”;
    include (‘ad.inc’);
    $my_id = 3;
    echo “</div><br><br>”;
    }
    else
    $my_id–;
    ?>

    You can see it in action here: https://certification.foundnews.com/

    PJ Brunet

    (@knowingart_com)

    “I don’t see any other template tags that are applicable. Is there an easy way to pull it from the database?”

    I would still like to know the answer to her original question…

    $post_id doesn’t seem to work, and there’s no tag for the page slug either ??

    PJ Brunet

    (@knowingart_com)

    Maybe I will need to extract the slug from the_permalink() ?

    Sounds yucky… ??

    $post->ID

    That works within The Loop.

    PJ Brunet

    (@knowingart_com)

    I love you, it worked! Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘post id number’ is closed to new replies.