Loading


Advertisement:

Author Topic: [SOLVED]How to display custom fields on listings  (Read 182 times)

fumi

  • Newbie
  • *
  • Posts: 27
[SOLVED]How to display custom fields on listings
« on: April 18, 2017, 06:22:51 pm »
Hello, I am using the OsclassWizards theme.
On the top page, below the categories, there's a list of recently posted ads, but I want to change what information it displays for each of these ads.
Right now, it shows the picture, category, the price, and the posted date.
I am making a website related to events, so the posted date is not really important, but I want to display the date of the event (I added this through customize field).

Is there any way to...
1) Remove posted date from displaying
2) Display the custom field that I added to the display

Thank you in advance!
« Last Edit: April 23, 2017, 02:06:34 am by fumi »

teseo

  • Hero Member
  • *****
  • Posts: 5721
Hi,

1.- Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_get_custom_field_value($name) {
    
$getItemMeta osc_get_item_meta();
    
$name '~^'preg_quote(htmlentities($name), '~') . '$~';
    
$index array_filter($getItemMeta, function($a) use($name)  {
        return 
preg_grep($name$a);
    }); 

    
$cf $getItemMeta[key($index)];

    if (
$cf['e_type'] == 'DATE' ) return osc_format_date(date('Y-m-d'$cf['s_value']));
    elseif (
$cf['e_type'] == 'DATEINTERVAL' ) return osc_format_date(date('Y-m-d'$cf['s_value']['from'])) . ' ' __('to') . ' ' osc_format_date(date('Y-m-d'$cf['s_value']['to']));
    else return 
$cf['s_value'];


?>


2.- Look for this line in osclasswizards/loop-list.php

Code: [Select]
                </span> <span class="date"> <i class="fa fa-clock-o"></i> <?php echo osc_format_date(osc_item_pub_date()); ?> </span>
Replace with:

Code: [Select]
                </span> <span class="date"> <i class="fa fa-clock-o"></i> <?php echo cust_get_custom_field_value('[EVENT DATE]'); ?> </span>
(Replace here [EVENT DATE] with the real name of your event custom field.

Regards

fumi

  • Newbie
  • *
  • Posts: 27
[SOLVED]How to display custom fields on listings
« Reply #2 on: April 18, 2017, 09:52:43 pm »
How do you know the answer to EVERYTHING?
Thank you so so much teseo!

teseo

  • Hero Member
  • *****
  • Posts: 5721
Re: [SOLVED]How to display custom fields on listings
« Reply #3 on: April 19, 2017, 03:33:54 pm »
 :D You're too kind, but of course I don't know everything, it's just that Custom fields is a matter I've been studying for a while.

You're welcome, regards

fumi

  • Newbie
  • *
  • Posts: 27
Re: [SOLVED]How to display custom fields on listings
« Reply #4 on: April 20, 2017, 05:13:42 pm »
teseo, can I please borrow your brain one more time?
I followed what you said, and the top page looks perfect.
But on all the other pages (for example, when you click a category from the top page or do a search), the listings are displaying the posted date instead of the event date that I want to display.
I am assuming that I have to add the same codes to other files, but could you please tell me which files I need to add to?

Thank you so so much!

fumi

  • Newbie
  • *
  • Posts: 27
Re: How to display custom fields on listings
« Reply #5 on: April 20, 2017, 07:04:47 pm »
sorry to keep messaging you teseo, but is there a possibility that this would affect the search function?
I had the customized field ("event date") added to the side-bar search and I remember it working fine, but now it's not working :(

I don't have enough knowledge to know what exactly caused this, but the only changes that I can think of is the change that I made for functions and loop-list as above and also the changes in the following link: https://forums.osclass.org/3-7-x/thank-you!/

If you have any idea, please let me know. THANK YOU!

teseo

  • Hero Member
  • *****
  • Posts: 5721
Re: [SOLVED]How to display custom fields on listings
« Reply #6 on: April 21, 2017, 02:20:43 pm »
Hi,

I am assuming that I have to add the same codes to other files, but could you please tell me which files I need to add to?

There are quite a few files, look for

osc_format_date(osc_item_pub_date()

in every script starting with "loop-"

BTW, you can replace the clock icon with a calendar:

Code: [Select]
class="fa fa-calendar">
Quote
I don't have enough knowledge to know what exactly caused this, but the only changes that I can think of is the change that I made for functions and loop-list as above and also the changes in the following link: https://forums.osclass.org/3-7-x/thank-you!/

First, I've detected now a bug on the code to have "universal" custom fields, see here for corrected code.

Regarding your problem, these modifications shouldn't provoke something like that ??? but anyway, try reverting them, see what happens...

Regards

fumi

  • Newbie
  • *
  • Posts: 27
Re: How to display custom fields on listings
« Reply #7 on: April 22, 2017, 05:36:22 am »
Thank you teseo!
I will try it this weekend and report you the results :)
Have a great weekend!

fumi

  • Newbie
  • *
  • Posts: 27
Re: How to display custom fields on listings
« Reply #8 on: April 23, 2017, 01:16:27 am »
I changed all the loop files and it worked!
I am also happy that I could change to a calendar icon :)
Thank you so so much!

My date search is still being weird, but I guess I'll just have to remove the "search by date" function because it's having other issues too.

Thanks again and hope you are having a great weekend!
« Last Edit: April 23, 2017, 02:06:15 am by fumi »