WebsiteBaker Support (2.8.x) > Templates, Menus & Design
hidding page content when empty
(1/1)
mtcook01:
Hi all I am having a php issue and I simply cannot figure it out. I am using the water and stone green template and trying not to show the center boxes if they are empty. The code in index.php is as follows.
<?php if (!empty page_content(2)) { ?>
<div id="content_top1">
<table cellpadding="0" cellspacing="0" class="moduletable">
<tr>
<th valign="top">
Popular News
</th>
</tr>
<tr>
<td>
<ul class="mostread">
<li class="mostread">
<?php page_content(2); ?>
</li>
</ul>
</td>
</tr>
</table>
</div>
<?php } ?>
This is mostly due to my VB knowledge and little to no php skills. I also tried the
if page_content(2) <> "" then show the content...
and that did not work at all. I have to guess that this is a coding issue and would greatly appreciate any help with the matter. Thanks for your time.
doc:
Hello,
please search the forum for ob_start, ob_get_contents which can be used to check if there is content in blocks or not.
Regards Christian
mtcook01:
Yes very sorry, I did a prior search but my brain dead self did not find the answer. After further investigation I found it and have fixed the problem. I have attached the code here just for anyone else's future use. Thanks for your time .
<!-- start content top 1. -->
<!-- added by Michael Cook to check for block content before dispalying -->
<div id="content_top1">
<?php
ob_start();
echo page_content(2);
$content2 = ob_get_contents();
ob_end_clean();
if ($content2<>"") { ?>
<table cellpadding="0" cellspacing="0" class="moduletable">
<tr>
<th valign="top">
Popular News
</th>
</tr>
<tr>
<td>
<ul class="mostread">
<li class="mostread">
<?php page_content(2); ?>
</li>
</ul>
</td>
</tr>
</table>
</div>
<?php } ?>
<!-- end content top 1 -->pre]
Navigation
[0] Message Index
Go to full version