• Hi, I have this code:

    <?php if (is_page('2')) { ?>
          <h3>Title</h3>
          <p>Text</p>
    
     <?php } ?>

    But it doesn’t work. Any solution?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Where do you have that code?
    What is it supposed to do? (according to you)
    Link to an example? Doesn’t work meaning… ?

    Thread Starter grunlof

    (@grunlof)

    Ok, I have that code in an include archive.
    At the end of the index.php I have the next code:

    <?php include (TEMPLATEPATH . '/columna3.php'); ?>

    And in this archive I have the is_page.
    If I am in a page with id=2, it must show me a title with some text. But nothing happens.

    So, is that conditonal in:
    – index.php?
    – columna3.php
    What is “include archive”?

    Thread Starter grunlof

    (@grunlof)

    The conditional is in columna3.php

    Do you have a page.php template file in your theme? If yes, then index.php is NOT used to display your page_id=2 – which means the code is useless in index.php.

    The conditional you are using is for Pages.

    Thread Starter grunlof

    (@grunlof)

    I dont’t understand. I have a page.php template file. But what can I do???
    columna3.php is called from index.php and from page.php. And never happens anything.

    If it is called into the page.php, too – then it should work.

    Give a link to your Page that has ID#=2.

    Thread Starter grunlof

    (@grunlof)

    https://www.address.com/page/

    [mod – you edited the address, and it is wrong now! your page_id=2 was the About Page]

    Put your columna3.php to https://wordpress.pastebin.ca and post back with the address

    Thread Starter grunlof

    (@grunlof)

    Thread Starter grunlof

    (@grunlof)

    I don’t know where is the problem. I have used the same in previous wordpress versions.

    Thread Starter grunlof

    (@grunlof)

    is functions don’t work. Any idea?

    Assuming you are wanting to put in your own text, you could do this, using echo to write the stuff you add:

    <?php if (is_page('2')) {
     echo('<h3>Your Title here</h3><p>your text content here</p>');}
    else {}
    
     ?>

    or, if you want to pull the actual title and content from the db, then you do something like:

    <?php if (is_page('2')) {
    the_title('<h2>','</h2>');
    the_content();
    }
    else {}
    
     ?>

    is that what you are after?

    HTH

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Problems with is_page()’ is closed to new replies.