Keyword

[SOLVED] K2 Content module - disabling some links

More
10 years 1 month ago #131020 by Jon
I am currently switching over my relatively small personal site over to K2 for some organizational improvements and more options with formatting, so it is not yet published.

Basically, I want to have a module on the frontpage that shows the latest site updates, this is currently a basic joomla Articles Category module, but I want to be able to include brief news snippets in addition to newly added pages. The thing is, I don't want these to be linked, as they will be short messages without any additional content or explanation. I want whether or not the title is linked to be determined by the category the article belongs to.

Basically:
Link 1
Link 2
Unlinked news 3 (from news category)
Link 4
Unlinked news 5 (from other news category)
Link 6
etc...

Should I be using the K2 Content module for this? Can I have the category determine whether the article title in the list is linked? Is there an existing plugin that would do this?

Any info would be appreciated, I am fairly new to K2 and less than comfortable with php, but have a hunch that the solution is not a particularly complex one.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #131021 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Content module - disabling some links
There is no setting for this but you can create an new K2 Content template.
Read this post first: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Then open the default.php file of the newly created mod_k2_content/default folder (or even better create a new template) and locate this lone of code:
<?php if($params->get('itemTitle')): ?>
      <a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>
      <?php endif; ?>

and replace it with:
<?php if($params->get('itemTitle')): ?>
      <?php echo $item->title; ?>
      <?php endif; ?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
10 years 1 month ago - 10 years 1 month ago #131022 by Jon
Thanks for the tip, I think I'm on the right track, but I think my file structure is preventing it from being implemented.

I've found the lines in question and made the change as well as made a new template, but I don't know if it is at the correct hierarchical level to be used - it is seen when editing my categories to assign its use - but the changes aren't implemented.

Currently, I have the 'full template' override that the guide lets you setup, but I've put the edited file in the root directory of the template override (/mytemplate/html/com_k2/overridetemplate/), named default as it was originally, named mod_k2_content, and named default but within a folder called mod_k2_content) and the changes don't seem to have been applied.

Should I be making s more localized override or does the modified file need to go in a directory relating to the component instead of the template?

Thanks!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #131023 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Content module - disabling some links
The folder for modules is the root folder of your overrides.

eg:
template/html/mod_k2_content/custom-modk2-template

The com_k2 folder refers to the component view which I do not think you need to edit at this point.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
10 years 1 month ago #131024 by Jon
That's the right place, I got it working with the code in place... but the functionality was a bit lacking. Basically, it just now displays every item listed in the module without links, instead of having some with and some without. I started mucking around with the php in the overriden template and managed to get a few things to compile, but now I think I'm polling the wrong variable.

What I'm trying to do is poll the name of the item's category, compare it to the names of categories I want to have unlinked (hardcoded into the override for now), and if it matches, only put up the title. Otherwise I want it to display the normal linked title. I've got this code:
      <?php if($params->get('itemTitle')): ?>
      <?php if($params->get('itemCategory')): ?>
      <?php echo $item->categoryName ; ?>
      <?php if(strncmp($item->categoryName,"Site News",9)==0||strncmp($item->categoryName,"Music News",10)==0): ?>
      <?php echo $item->title; ?>
      <?php else: ?>
      <?php echo "<a class='moduleItemTitle' href='" . $item->link . " ?>" . $item->title . "</a>" ; ?>
      <?php endif; ?>
      <?php endif; ?>
      <?php endif; ?>

But currently the output is nothing, even from the echo statement inside the second if, though I have verified in modifying the code that it is still executing at least through the first if statement correctly. I've tried some variations on this, including using the original link displaying code without the "<?php echo" header, but at the time I was getting all linked titles and was wondering if it was somehow outside the correct nested if... this flow control looks very strange to my eyes.


Any help you can offer for calling the item's category name from within the module to determine which output happens would be helpful.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #131025 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Content module - disabling some links
You should perform a check using the category's id.

Example:
if($item->categoryid == 'ID HERE' ) {
// execute some code
}

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
10 years 1 month ago #131026 by Jon
Perfect! Got it working, now just have to get the formatting in line with the original articles categories and I'll be swapping over to use k2 for the important bits.


Thanks for the help!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 1 month ago #131027 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Content module - disabling some links
You 're welcome Jon.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum