0

I have an if statement which shows a countdown only on Sundays and Wednesdays. But, I need to add padding to the body as well for it to display correctly.

So basically I need to add padding to the body when a line of php is executed.

Is this possible?

2
  • do you do inline css(style="") or use a css file? Commented Jul 11, 2012 at 20:51
  • What is the basic setup of your site? It's difficult to make a recommendation unless we can consider more context. Commented Jul 11, 2012 at 20:51

2 Answers 2

4

To keep your styles and HTML separate, you can add a class to the body based on the same if statement. Then use your CSS to add styles to that class:

<?php 
$dayOfWeek = date( "w", $timestamp);
if ($dayOfWeek == 0 || $dayOfWeek == 3) { ?>
    <body class="withCountdown">
<?php } else { ?>
    <body>
<?php } ?>

body.withCountdown {
    padding: 10px;
}

(Excuse my rusty PHP syntax!)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this worked! I did change the upper portion to: <?php $today = date('N'); if($today == 3 or $today == 7) { ?> which worked for me.
0
<body style="padding:<?php echo(is_sunday() ? '4px' : '0' );?>" >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.