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
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?

 

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.