0

I have a site where the pages have the following structure:

<?php
    include('header.php');
?>

Content goes here

<?php
    include('footer.php');
?>

In the header I have a div that contains anything that is wider than the page itself. This div is above the main content:

<? if ($slider == true){ ?>

    <div id="slider">
       Content wider than page goes here
    </div>

If I set $slider to true on any page, the above div will show. Now, I want to be able to edit the content of this div from any page. How do I do this? Simply adding a variable like $slider_content and then including it in the header did not work.

2
  • 1
    In your sample HTML, did you mean to include header.php twice? Commented Jun 28, 2012 at 16:23
  • How about creating a function that takes the content as an argument? Commented Jun 28, 2012 at 16:26

2 Answers 2

1

If that's what you mean...

<?php
    $slider_content = 'foo';

    include('header.php');
?>

Content goes here

<?php
    include('footer.php');
?>

And your slider:

<div id="slider">
   <?=$slider_content?>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

That worked. I tried the exact same approach myself, but it didn't work. Only difference was the = in <?=$slider_content?>. Can you explain why that works, and not using the = doesn't?
<?=$variable?> outputs given $variable. It's the same as writing <?php echo $variable?>. Please accept my answer if it worked for you :)
0

I suggest you add something like this in your included header.php:

<?php if (isset($_GET['edit-content'])): ?>
    make the content editable here
<?php else: ?>
<div id="slider">
   Content wider than page goes here
</div>
<?php endif; ?>

Then you simply add a edit button if the goal here was to edit the actual content of your slider from any given page.

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.