Get Tag links per post like Blog Module

edited June 2016 in Modules
I would like to generate tag links for my event module record class just like how the Blog Posts model class handles it.
However I'm a bit confused on how to generate the right parameters for the anchor function. So I would like to generate links of this format: www.example.com/events/tags/car

function get_tags_linked($order = 'name asc', $join = ', ', $link_params = array())
{
$tags = $this->tags;
if ( ! empty($tags))
{
$tags_linked = array();
foreach ($tags as $tag)
{
$tags_linked[] = anchor($this->_CI->fuel->blog->url($tag->get_url(FALSE)), $tag->name, $link_params);
}
$return = implode($tags_linked, $join);
return $return;
}
return NULL;
}

Comments

  • edited 6:11PM
    I'm not quite sure I'm understanding the question, however, if I were to guess, it would be the first parameter:
    $this->_CI->fuel->blog->url($tag->get_url(FALSE)), $tag->name, $link_params);
    That is the URL that is generated from the blog and the tag. In your case, you would want something like the following:
    ... $tags_linked[] = anchor(site_url('events/tags/'.$tag->slug), $tag->name, $link_params); ...
  • edited 6:11PM
    Ah wrong choice of words, I should have been clearer. But you're correct, I was confused about getting the right URL for the anchor function. Thanks for clearing things up.
  • edited 6:11PM
    I ran into some URL resolving issues on event tags page. When i'm on the events tags page e.g. www.example.com/events/tags/car all my links become broken as it resolves to something like this: www.example.com/events/tags/blog or www.example.com/events/tags/home . All my links on this page becomes like this and treats www.example.com/events/tags as the Base URL where things gets appended to this URL.

    I assume it's because of how I handle the requests for event tags to my tags view.
    $pages['events/tags/:any'] = array('view' => 'events/tags');

    Do you have any clue why this is happening? I've ran into this before with CodeIgniter.
  • edited 6:11PM
    Here is the code for my tags.php file:

    <?php
    $slug = uri_segment(3);

    if ($slug) :
    $tag = $CI->fuel->tags->find_by_tag($slug);
    if (empty($tag)) :
    redirect_404();
    endif;

    $events_model = $tag->get_events(TRUE);

    $events = $events_model->find_all(array('event_startdate >=' => datetime_now()), 'event_startdate', $limit, $offset, NULL, NULL);
    $vars['events'] = $events;
    endif;
    ?>

    <?=ucfirst($slug)?> Events

    <?=$this->load->view('_blocks/event_posts', $vars)?>


    P.S. how do I markdown code by the way?
  • edited 6:11PM
    I was able to resolve it, it seems I was changing the config value for base url in my view code. I was trying to get pagination to work for my tags page. So I loaded the pagination library and my pagination config file, which had a config item with $config[base_url] = NULL. So I tried changing this value in my tags view file to $config[base_url] = base_url('events/tags/' . $slug). I assume I was changing the base url config from config.php instead of paginations.php.
Sign In or Register to comment.