php if then question

More
13 years 10 months ago #7437 by intown
php if then question was created by intown
This may be a simple php question.

What would be the proper to code to show a custom field if it exists and if it does not show the page title?

Here are my two blocks of code

Custom Field
Code:
<!-- BOF intro-left block --> <?php if (isset($this->item->positions['intro-left'])) : ?> <div class="lineinfo intro-left"> <?php foreach ($this->item->positions['intro-left'] as $field) : ?> <span class="element"> <?php if ($field->label) : ?> <span class="label field_<?php echo $field->name; ?>"><?php echo $field->label; ?></span> <?php endif; ?> <span class="value field_<?php echo $field->name; ?>"><?php echo $field->display; ?></span> <?php endforeach; ?> </div> <?php endif; ?> <!-- EOF intro-left block -->

Page Title
Code:
<!-- BOF item title --> <?php if ($this->params->get('show_title', 1)) : ?> <h2 class="contentheading flexicontent"> <?php echo $this->escape($this->item->title); ?> </h2> <?php endif; ?> <!-- EOF item title -->

Just not sure of the syntax to display the page title if no intro-left fields exist.

Thanks!

Please Log in or Create an account to join the conversation.

More
13 years 10 months ago #7438 by intown
Replied by intown on topic php if then question
Thinking about it a little more. Could a statement like this work?
Code:
<?php if (isset($this->item->positions['intro-left'])) : ?> do nothing else <?php echo $this->escape($this->item->title); ?> (show the page title)

Just need to figure out what the correct code would be.

After some trial and error, I came up with this code which seems to work
Code:
<?php if (isset($this->item->positions['intro-left'])) : ?> <?php else : ?> <h2 class="contentheading flexicontent"> <?php echo $this->escape($this->item->title); ?> </h2> <?php endif; ?>

Is there a better way to accomplish my goal?

Thanks!

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.330 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline