Forums

Wordpress page_id in a loop - not working with enhanced permalinks (3 posts)

  1. jockerworks
    Member
    Posted 1 year ago #

    Hello everyone, I am having a little problem with a list of links to wordpress pages. This is what I am trying to implement:

    <?php if ($page_id == '2') {echo "
    <li class=\"current\">Profile
    ";}
    else {echo "

  2. Profile
  3. ";} ?>

    To put it simple it is supposed to be a system printing different text depending on the current page id. That way I can give a .current class to a li element, like I do in the example. It always worked flawlessly until the moment I activated a different kind of permalinks to have a more user friendly URL for the blog pages. I do not know wordpress in depth and I did not find enough informations on the matter around the web. Would anybody mind giving me a couple of things on how to solve this problem, maybe a workaround or a easier system ro recognize the page I am in in wordpress and how to use it in a php loop?

    Thanks everyone.

  • jockerworks
    Member
    Posted 1 year ago #

    mmh, maybe I did not really give an attractive title to this topic... any tips anyone? :(

  • SinusCom
    Member
    Posted 1 year ago #

    I don't know if you find a solution for your problem but this isthe one it works fine:

    <?php
    if ( is_page('2')) {
           echo ("BLABLABLA");
        }
        else {
           echo ("Second BLABLABLA");
         }
    ?>

    2 is your page id.

    Cheers,
    $me

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags