Jump to content

Variable content width


goocharlton

Recommended Posts

I have a content area with width that varies according to whether there are left or right modules(this is a joomla cms site).

 

I have written this code but I cant get it to work....

<div id="content" style="width:<?php
					if ((mosCountModules( "left" )) < 0):
						if ((mosCountModules( "right" )) < 0)
						echo "800";; 
					elseif ((mosCountModules( "left" )) > 0):
						if ((mosCountModules( "right" )) > 0)
						echo "380";;
					 elseif ((mosCountModules( "left" )) < 0):
						if ((mosCountModules( "right" )) > 0)
						echo "590";; 
					 elseif ((mosCountModules( "left" )) > 0):
					 	if ((mosCountModules( "right" )) < 0)
						echo "590";; 
					endif;
					?>px">											
			</div>

 

Can anyone tell me what I am doing wrong, if you dont know anything about Joomla do you know whats wrong with the php i have writen?. I am trying to say that:

- If there are no modules in the left AND right columns echo a width of 800px.

- If there are modules in the left AND right columns echo a width of 380px.

- If there are modules in the right AND not in the left columns echo a width of 590px.

- If there are modules in the left AND not in the right columns echo a width of 590px.

Link to comment
https://forums.phpfreaks.com/topic/67694-variable-content-width/
Share on other sites

I have a content area with width that varies according to whether there are left or right modules(this is a joomla cms site).

 

I have written this code but I cant get it to work....

<div id="content" style="width:<?php
					if ((mosCountModules( "left" )) < 0):
						if ((mosCountModules( "right" )) < 0)
						echo "800";; 
					elseif ((mosCountModules( "left" )) > 0):
						if ((mosCountModules( "right" )) > 0)
						echo "380";;
					 elseif ((mosCountModules( "left" )) < 0):
						if ((mosCountModules( "right" )) > 0)
						echo "590";; 
					 elseif ((mosCountModules( "left" )) > 0):
					 	if ((mosCountModules( "right" )) < 0)
						echo "590";; 
					endif;
					?>px">											
			</div>

 

Can anyone tell me what I am doing wrong, if you dont know anything about Joomla do you know whats wrong with the php i have writen?. I am trying to say that:

- If there are no modules in the left AND right columns echo a width of 800px.

- If there are modules in the left AND right columns echo a width of 380px.

- If there are modules in the right AND not in the left columns echo a width of 590px.

- If there are modules in the left AND not in the right columns echo a width of 590px.

 

<div id="content" style="width:<?php
					if ((mosCountModules( "left" )) < 0) {
						if ((mosCountModules( "right" )) < 0)
						echo "800";
					}
					elseif ((mosCountModules( "left" )) > 0)
					{
						if ((mosCountModules( "right" )) > 0)
						echo "380";
					}
					 elseif ((mosCountModules( "left" )) < 0)
					 {
						if ((mosCountModules( "right" )) > 0)
						echo "590";
					}
					 elseif ((mosCountModules( "left" )) > 0)
					 {
					 	if ((mosCountModules( "right" )) < 0)
						echo "590";; 
					}
					?>px">											
			</div>

 

Your syntax was completely wrong?

 

<div id="content" style="width:<?php
					if ((mosCountModules( "left" )) < 0) {
						if ((mosCountModules( "right" )) < 0)
						echo "800";
					}
					elseif ((mosCountModules( "left" )) > 0)
					{
						if ((mosCountModules( "right" )) > 0)
						echo "380";
					}
					 elseif ((mosCountModules( "left" )) < 0)
					 {
						if ((mosCountModules( "right" )) > 0)
						echo "590";
					}
					 elseif ((mosCountModules( "left" )) > 0)
					 {
					 	if ((mosCountModules( "right" )) < 0)
						echo "590";; 
					}
					?>px">											
			</div>

 

Your syntax was completely wrong?

 

 

Umm... no, his syntax was not completely wrong. I suggest you look into http://www.php.net/manual/en/control-structures.alternative-syntax.php . However, his logic is. Try this:

<div id="content" style="width:<?php
                                if ((mosCountModules('left') && mosCountModules('right')) < '0'):
                                    echo '800';
                                elseif ((mosCountModules('right') && mosCountModules('left')) > '0'):
                                    echo '380';
                                elseif ((mosCountModules('left') < '0') && (mosCountModules( "right" ) > '0')):
                                    echo '590';
                                elseif ((mosCountModules('right') < '0') && (mosCountModules( "left" ) > '0')):
                                    echo '590';
                                endif;
                               ?>px">
</div>

Just wondering, but don't you have to cut a gaping hole?

 

<<If wondering what the hell I am on about, look for the quotation marks>>

 

echo "<div id='content' style='width:"<?php
                                if ((mosCountModules('left') && mosCountModules('right')) < '0'):
                                    echo '800';
                                elseif ((mosCountModules('right') && mosCountModules('left')) > '0'):
                                    echo '380';
                                elseif ((mosCountModules('left') < '0') && (mosCountModules( "right" ) > '0')):
                                    echo '590';
                                elseif ((mosCountModules('right') < '0') && (mosCountModules( "left" ) > '0')):
                                    echo '590';
                                endif;
                               ?>"px'>
</div>";

PHP can be embedded in html, so there is no problem with the way he's doing it. Take a look at http://www.php.net/manual/en/language.basic-syntax.php & http://www.php.net/manual/en/language.types.string.php . Hopefully those will give you a better understanding.

 

Your method is fine for strings (<a href="http://www.php.net/manual/en/language.operators.string.php">concatenation operator</a>), but that is kinda irrelevant to this topic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.