0

I am doing a category blog override. As part of that I require the blog item URL. Not the current URL, which I can get, the read more URL of the blog.

I tried to create a JLayout override, and strip everything except the URL, but that hasn't worked. I get the error:

Cannot use object of type stdClass as array

I'm not much of a programmer, but I'm a bit confused as to why this won't work but it will for a normal JLayout. All I did was remove some stuff.

1

I found a better way of doing this.

<a href="
    <?php echo 
        JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, 
                    $this->item->catid, $this->item->language)); 
    ?>
">Learn More</a>
1

I found another even better way of doing this.

<?php echo $item->link; ?>
  • Lol...nicely refactored – BodgeIT Oct 7 '16 at 17:39
0

I worked out how to do this. There is probably a MUCH better way, but this is how I did it.

Create my JLayout override

First of all, I went to my Joomla! site. I went to layouts/joomla/content/blog_style_default_item_title.php

I resaved that file in a new location:

templates/YOUR_TEMPLATES_NAME/html/layouts/joomla/content/

I renamed it, blog_style_default_URL.php

Edit the new JLayout override

Now, I can go into this new layout file, strip the <h2> and the <a> leaving just the URL. In this instance, I know that I will always have linked titles, so I can remove the if statement too. I could probably strip everything and just leave:

<?php echo 
    JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, 
    $displayData->catid, $displayData->language)); 
?>

Create my HTML override, and call my JLayout

Now I create my HTML override (I won't cover how to do that), in my blog override, blog_item.php, I call the layout. JLayoutHelper::render('joomla.content.blog_style_default_item_url', $this->item);

That gives me my url, but it only provides index.php/21-my-blog-item.php

Find the Base URL and append it

We need the base url too. So I use:

<?php echo 
    $url . JLayoutHelper::render('joomla.content.blog_style_default_item_url', 
    $this->item); 
?>

Remove the trailing slash (if included)

Now I have my url, but I have two slashes. Doh.

www.mywebsite.com//index.php/21-my-blog-item.php

So I used:

<?php 
  // Get the base URL & trip the slash
  $url            = JURI::base();
  $url            = $url = rtrim($url, '/');
?>

Final code

Now in my url I have:

<a href="
    <?php echo 
        $url . JLayoutHelper::render('joomla.content.blog_style_default_item_url', 
        $this->item); 
    ?>" 
</a>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.