- Posts: 6
COMMUNITY FORUM
Hyperlink Titles in Category
- Theo Cody
-
Topic Author
- Offline
- New Member
Less
More
10 years 6 months ago #133181
by Theo Cody
Hyperlink Titles in Category was created by Theo Cody
Hello,
I am trying my hands on a news portal but i am not good at codes.
How do i make my titles link to an external webpage (hyperlink) or target="_blank" sort of.
I am using the categories display in my menu setup so i want some of my titles to link directly to original page source.
how do i go about this in a step-by-step manner. Any help will be appreciated.
Thanks
I am trying my hands on a news portal but i am not good at codes.
How do i make my titles link to an external webpage (hyperlink) or target="_blank" sort of.
I am using the categories display in my menu setup so i want some of my titles to link directly to original page source.
how do i go about this in a step-by-step manner. Any help will be appreciated.
Thanks
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 6 months ago #133182
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Hyperlink Titles in Category
You need to override your K2 template.
This post will help you. getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Then you need to create a text type extrafield for the link.
You can directly render extrafields like this:This will print the value of a specific extrafield. Replace the EXTRAFIELD alias with the actual alias.
Now in category_item.php you need to perform a simple check. If that field both exists and has a value print that instead of $this->item->link.
This post will help you. getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Then you need to create a text type extrafield for the link.
You can directly render extrafields like this:
<?php echo $this->item->extraFields->EXTRAFIELDALIAS->value ?>
Now in category_item.php you need to perform a simple check. If that field both exists and has a value print that instead of $this->item->link.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Theo Cody
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 6 months ago - 10 years 6 months ago #133183
by Theo Cody
Replied by Theo Cody on topic Re: Hyperlink Titles in Category
Krikor,
I appreciate you trying to help. I really do. Like i said before am not very good with codes.
However i was able to create the overrides from joomla back end.
Would you try explaining to me in a more simplified way? How do i make my titles link to an external webpage (hyperlink) or target="_blank" sort of. step-by-step?
Thanks.
I appreciate you trying to help. I really do. Like i said before am not very good with codes.
However i was able to create the overrides from joomla back end.
Would you try explaining to me in a more simplified way? How do i make my titles link to an external webpage (hyperlink) or target="_blank" sort of. step-by-step?
Thanks.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 6 months ago #133184
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Hyperlink Titles in Category
The overrides have to be created with the method I posted.
After you have the extrafield setup read this tutorial and open the category_item.php file
www.w3schools.com/php/php_if_else.asp
Check if that extrafield's value is not blank:
You need to replace all instances ofwith
You can also set the link as a variable, perform only one check and echo that variable instead.
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ) {
$linkcat = $this->item->extraFields->EXTRAFIELDALIAS->value
} else {
$linkcat = $this->item->link;
}?>
and then echo $linkcat where you need to change the link.
After you have the extrafield setup read this tutorial and open the category_item.php file
www.w3schools.com/php/php_if_else.asp
Check if that extrafield's value is not blank:
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ) {
// DO STUFF
}?>
You need to replace all instances of
href="<?php echo $this->item->link; ?>"
href="<?php echo $this->item->extraFields->EXTRAFIELDALIAS->value ?>"
You can also set the link as a variable, perform only one check and echo that variable instead.
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ) {
$linkcat = $this->item->extraFields->EXTRAFIELDALIAS->value
} else {
$linkcat = $this->item->link;
}?>
and then echo $linkcat where you need to change the link.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Theo Cody
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 6 months ago #133185
by Theo Cody
Replied by Theo Cody on topic Re: Hyperlink Titles in Category
Hello Krikor,
I have done the override and I have created the extrafield.
What do I put in the extrafield space when creating an item? Is it the source url?
In my category_item.php file I see this:
<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>
I want to use the PHP- The if…….else statement.
Syntax
if (condition) {
code to be executed if there is an extrafield value to item source;
} else {
item title code to be executed if no extrafield value;
}
I hope i made some sense.......
Thanks again.
I have done the override and I have created the extrafield.
What do I put in the extrafield space when creating an item? Is it the source url?
In my category_item.php file I see this:
<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>
I want to use the PHP- The if…….else statement.
Syntax
if (condition) {
code to be executed if there is an extrafield value to item source;
} else {
item title code to be executed if no extrafield value;
}
I hope i made some sense.......
Thanks again.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
Less
More
- Posts: 8743
10 years 5 months ago - 10 years 5 months ago #133186
by Lefteris
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Lefteris on topic Re: Hyperlink Titles in Category
@Theo Cody
Krikor has already provided the code for that:
Krikor has already provided the code for that:
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ): ?>
<a href="<?php echo $this->item->extraFields->EXTRAFIELDALIAS->value; ?>"><?php echo $this->item->title; ?></a>
<?php else: ?>
<a href="<?php echo $this->item->link; ?>"><?php echo $this->item->title; ?></a>
<?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.
- Theo Cody
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
10 years 5 months ago - 10 years 5 months ago #133187
by Theo Cody
Replied by Theo Cody on topic Re: Hyperlink Titles in Category
Hello Lefteris,
If i understand right, i basically have to
Replace:
<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>
With
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ): ?>
<a href="<?php echo $this->item->extraFields->EXTRAFIELDALIAS->value; ?>"><?php echo $this->item->title; ?></a>
<?php else: ?>
<a href="<?php echo $this->item->link; ?>"><?php echo $this->item->title; ?></a>
<?php endif; ?>
One last thing.
Krikor said "Then you need to create a text type extrafield for the link. This will print the value of a specific extrafield. Replace the EXTRAFIELD alias with the actual alias." Can i get some explanation on this please?
When i go to item-extrafield, what do I put in the extrafield space? Is it the source url?
I am trying to illustrate with some png images but the images simply wont load. Dont know what am doing wrong.
Sorry for being a slow learner.
If i understand right, i basically have to
Replace:
<?php if ($this->item->params->get('catItemTitleLinked')): ?>
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
<?php else: ?>
<?php echo $this->item->title; ?>
<?php endif; ?>
With
<?php if($this->item->extraFields->EXTRAFIELDALIAS->value != '' ): ?>
<a href="<?php echo $this->item->extraFields->EXTRAFIELDALIAS->value; ?>"><?php echo $this->item->title; ?></a>
<?php else: ?>
<a href="<?php echo $this->item->link; ?>"><?php echo $this->item->title; ?></a>
<?php endif; ?>
One last thing.
Krikor said "Then you need to create a text type extrafield for the link. This will print the value of a specific extrafield. Replace the EXTRAFIELD alias with the actual alias." Can i get some explanation on this please?
When i go to item-extrafield, what do I put in the extrafield space? Is it the source url?
I am trying to illustrate with some png images but the images simply wont load. Dont know what am doing wrong.
Sorry for being a slow learner.
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
Less
More
- Posts: 8743
10 years 5 months ago #133188
by Lefteris
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Lefteris on topic Re: Hyperlink Titles in Category
No, you didn't understand correctly. You need to just replace the line that prints the link:Regarding the extra fields alias you can set it when you create the extra field at the administration of K2.
<a href="<?php echo $this->item->link; ?>">
<?php echo $this->item->title; ?>
</a>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.