In Joomla (both 3x and 4x) I am trying to add a php 'if' query to a category blog override so that if the category title is 'X' then it does one thing, but if not, do something else. (I'm having trouble getting multiple overrides to work - but that's another issue - so I'm attempting to put two layouts into one override as a workaround.) Something like this:

$catTitle = ($item->displayCategoryTitle); in addition to the first 30-odd lines in the blog.php file

followed by the layout:

<?php if ($catTitle == 'myCategoryTitle') : ?>
<div class="outer-wrap">
    <?php foreach ($this->intro_items as $key => &$item) : ?>
        <div class="item-wrap">
            $this->item = &$item;
            echo $this->loadTemplate('item');
    <?php endforeach; ?>
<? php endif; ?>

...followed by the other layout. Presumably I may need an <?php else if ...? or <?php if ($catTitle != 'myCategoryTitle') : ?>

At the moment, I'm - not surprisingly - just getting a blank screen.

  • The post title is about converting a field to a string but the body is about issues with If/then so I am not sure what you are having the issue with. Which field value are you wanting to convert, $catTitle? If you do a printr($catTitle) just before the first 'if' statement what does it look like?
    – Irata
    Jan 14 at 22:58
  • Ok. I got the multiple overrides to work in the end, so this question is redundant. Sorry about the confusion over the 'string' nd 'if' statements.
    – Gillian
    22 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.