Гость
19 Фев 2018 06:07

Hello,

I am customizing a template to add schema.org code. I have figured out where to put most of the extra coding in the templates (copies of the templates).

However I need to pull the postion order as a number / text number. Since it is a dynamic position / order, it is always changing, depending on which search or category listing people have done. But I don't know php very well, so I don't know how to pull that value.

Each item in the list view is given a position, based on that page as displayed.

Here is part of the coding that I've customized:

<td itemprop="item" width="<?php echo $pos1width;?>" style="width: <?php echo $pos1width;?>" class="<?php echo $item->fields_by_key[$pos1]->params->get('core.field_class')?>"> <meta itemprop="position" content="1"> <span itemprop="item"><?php echo $result; ?></span></td>

The part that I need to put this value for is this line:

<meta itemprop="position" content="1">

Where it is showing "1" is where I need it to put that number.

You can see a sample page live here: Click here to go to link...

So, on this page example the line should show in this order, for these recipes:

Cinnamon Sugar Popcorn Seasoning

<meta itemprop="position" content="1">

French Fry Seasoning

<meta itemprop="position" content="2">

Fresh Herb Sprinkle for Vegetables

<meta itemprop="position" content="3">

Seasoning Salt

<meta itemprop="position" content="4">

Basically it's just the position of the items on the page, at that time. Sort of like an ordered list.

Maybe there is some sort of simple counter / order code that would work, so if that's what would it should be, then let me know.

Thank you.

Thora


pepperstreet VIP
Total posts: 3,837
19 Фев 2018 09:27

Hello Thora, it's been a while ;) If you have tried to reach me via business mail address... I can't access it due to some technical issues. Sorry, I am working on it. Alternatively, you can find me on facebook.


Counting and numbering your records/items

Search for the output loop:
<?php foreach ($this->items AS $item):?>

Right before that line, you can create and initialize a "counter". Name it to your liking. Maybe a simple x for index, or something that describes the purpose:

<?php $counter = 1; ?>

Then add the following line, where you want the output to be:

<meta itemprop="position" content="<?php echo $counter++; ?>">

Hope this helps.


pepperstreet VIP
Total posts: 3,837
19 Фев 2018 11:05

Counting and numbering your records/items (Alternative)

Just found another way and slightly different syntax.
Again, search for the output loop:
<?php foreach ($this->items AS $item):?>

Modify and add $index => like so:

<?php foreach ($this->items AS $index => $item):?>

You could also change the name index. Then output the meta tag and counter. You have to add +1, because it starts at 0:

<meta itemprop="position" content="<?php echo $index+1; ?>">

pepperstreet VIP
Total posts: 3,837
19 Фев 2018 11:21

Screenshot / Results

cob8_template_records_counter_index


tofty VIP
Total posts: 54
19 Фев 2018 16:59

Hi Pepperstreet!

Thank you, that worked perfectly!

Sent you a friend request on FB.

Cheers!

Thora

Работает на Cobalt