0

I've created a very simple slideshow module. I have a helper.php that gives me all articles of a given category. My problem is that i don't know how to create the readmore link.

That's what i have:

public static function getSildes() {
    // return var having the complete carousel stuff
    $slide = ""; 
    // a counter for bootstrap active flag
    $counter = 0;

    // my database connection
    $db = JFactory::getDbo();

    // i need the cat_id of category named "Bootyslide"
    $module = JModuleHelper::getModule('mod_bootyslide');
    $category = new JRegistry($module->params);
    $cat_id = (int) $category['mycategory'];

    // and now i select all the articles with the category id
    $query = $db->getQuery(true);
    $query->select('*');
    $query->from('#__content');
    $query->where('catid="' . $cat_id . '"');
    $query->where('state="1"');
    $db->setQuery((string)$query);
    $results = $db->loadObjectList();


    foreach($results as $result){
        $images  = json_decode($result->images);
        $image = $images->image_fulltext;
        $text = $result->introtext;
        $alias = $result->alias;
        $fulltext = $result->fulltext;
        ($counter == 0) ? $active = "active" : $active = "";
        $slide .= " <div class=\"item " . $active . "\">";

        if (strlen($image) > 0) {
            $slide .= "     <img src=\"" . $image . "\">";
        }
        $slide .= " <div class=\"carousel-caption\">
                        <div class=\"container\">
                            <div>
                                " . $text . "
                            </div>
                            <!-- the readmore link -->
                        </div>
                    </div>
                </div> ";
        ++$counter;
    }

    return $slide;

}

I know that when the column fulltext has values, I should create the readmore link, that's not the problem. I really don't know how to create the URL.

1 Answer 1

0

Try the following

<a href="<?php echo $result->link; ?>">Read more</a>

For some reason assumed you were using the content model...my bad.

Try this:

<?php
    $link = JRoute::_('index.php?option=com_content&view=article&id=' . $result->id);
    echo '<a href="' . $link . '">Read more</a>
?>

But just on a side note, I would suggest you put all your HTML in the default.php as this file is supposed to be used for all your markup, allowing users to create Template Overrides.

3
  • 1
    +1 on default.php, especially on a slideshow, where people reasonably might want to adjust output to match the site. (Since they are used as graphical elements.) Feb 18, 2015 at 11:47
  • $result->link is empty, I get the notice: Undefined property: stdClass::$link in ... Feb 18, 2015 at 12:04
  • @DaFunkyAlex - I've updated my answer
    – Lodder
    Feb 18, 2015 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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