Support » Themes and Templates » can I use a conditional Tag here?

  • Hello!
    I am new here.
    First of all – Thank you WordPress!

    I have a question about a conditional tag:

    There is a website with normal static pages, and some template pages – and one password-protected page.

    I have two problems
    1. This one page should be password protected – so I can’t use a template page – because somehow it’s not password protected then. (I don’t know how to make template pages password-protected).

    2. The password-protected page is using the “standard-template” because that’s the only way for me to get the passwordprotection work.
    The problem is – it uses the same css and div elements like the other pages – when I try to customize the post boxes – it’s not working, because when I change it, it changes on all pages…

    Well – my idea: Should I use conditional tags?

    here is the php code:

    <?php get_header(); ?>
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="page-title"><h1><?php the_title(); ?></h1></div>
    				<a href="javascript:history.back()">&laquo;&laquo;</a>
    				<div class="post-body-2">
    					<?php edit_post_link('Edit this page.', '<p>', '</p>'); ?>
    					<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    					<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				</div><?php echo get_post_meta($post->ID, "Camera_Specs", true); ?>
    		<?php endwhile; endif; ?>
    		<?php comments_template(); ?>
    <?php get_footer(); ?>

    I would like to have something that says: if_is_page('1508') echo "post-body-new-width something like that. I am total new to php.

    So I don’t know where to put the code…

    Maybe someone could give me a hint?!

    Thank you very much!



Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael


    Forum Moderator

    you could do that; i would add the conditional class here:

    <div class="post<?php if(is_page('1508') echo " post-body-new-width"; ?> id="post-<?php the_ID(); ?>">

    that would give you a class to format in the css file (style.css) – for instance: { ... } .post-title { ... }

    or check the wordpress template tag body_class() – that would give you additional classes depending on your template files, etc.

    edit header.php and change
    <body <?php body_class(); ?>>

    and then check in the browser which particular specific classes are in the body tag of your password protected page; and use them im style.css; for instance:

    .particular_template_class .post { ... }

    Dear alchymyth,

    thanks a lot for your reply! I tried your first suggestion,

    <div class="post<?php if(is_page('1508') echo " post-body-new-width"; ?> id="post-<?php the_ID(); ?>">

    but I got this error:

    Parse error: syntax error, unexpected T_ECHO

    I will try the ohter suggestions as soon as possible!

    Thank you for your help!




    Forum Moderator

    Try <div class="post<?php if(is_page('1508') ) echo " post-body-new-width"; ?> id="post-<?php the_ID(); ?>">

    Hi esmi,

    thank you! It worked – I can see now the code in HTML. But I found out, that it would be better (for me as noob) to just replace or remove the class:

    <div class="post-body-2">

    Because after this, I could make a new “box” class and enter the width for that specific page.

    Is there any way to remove the class with php – in this case on page 1508?

    Thank you guys very much!




    Forum Moderator

    See alchymyth’s second suggestion for using body_class().

    Hi! Alright! Finally it worked how you told me!

    I just had some problems with the css. But now it works.

    Thank you for your help!!!!



Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘can I use a conditional Tag here?’ is closed to new replies.