Keyword

Simple code to display item data

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
10 years 6 months ago #126427 by Joe Campbell
Simple code to display item data was created by Joe Campbell
I have found on this forum a simple one line of code to display Extra Fields by way of its alias...thanks K2 Admins...<?php echo $this->item->extraFields->AliasHere->value; ?>

Is there a simple line of code to display basic K2 Item info, such as
  • Title
  • Category
  • Author

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

More
10 years 6 months ago #126428 by Lefteris
Replied by Lefteris on topic Re: Simple code to display item data
Hi. This depends on the context ( item view, category view etc.). You can take a look at the bundled templates of K2 to see how they are using the variables to output the properties you need. For example item title can be used like :
<?php echo $this->item->title; ?>

Note that depending on context you might need to use :
$item
instead of
$this->item

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

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

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
10 years 6 months ago #126429 by Joe Campbell
Replied by Joe Campbell on topic Re: Simple code to display item data
I would like to execute for an Item, saying that, I just tried the following...
<?php echo $this->item->title; ?>
<?php echo $this->item->category; ?>
<?php echo $this->item->author; ?>

The Results...

Title - displayed properly
Category - displayed the following text "TableK2Category"
Author - displayed nothing at all

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

More
10 years 6 months ago #126430 by Lefteris
Replied by Lefteris on topic Re: Simple code to display item data
I didn't tell you to use this code for category and author. I told you to look at the code K2 templates use.

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