• Hi Greg,

    A couple of things that you can hopefully help with!

    The first is how to get a URL link in an adverts details to open in a new window, ie. have the target as _blank. Basically i have added in a field for a URL in a custom form that i set up for new adverts. However, the URL will appear with the other details in the advert listing, but when clicked it opens in the same tab, whereas i want it to open in a new window, so as not to let users be directed away from my site.

    Secondly, is it possible to display the user name of a seller on the adverts list? We have various retailers using our site and we want to be able to have their name displayed on the initial adverts list, so as users can see what retailer is advertising, without having to click into the advert.

    Thanks for the help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    1. i understand you have a custom field added to [adverts_add] form which contains the URL? If so then can you let me know how the field was added? Was it done using the Custom Fields extensions or the Forms API?

    2. you can include additional data after the title using adverts_list_after_title filter like this

    
    add_action( "adverts_list_after_title", function( $post_id ) {
      echo '<strong>' . get_post_meta( $post_id, 'retailer_name', true ) . '</strong>';
    } );
    

    This will, of course, work only if the retailer name is stored in a field named ‘retailer_name’ if not then you would need to customize the code.

    If you would like to place the retailer name somewhere else (not after the title) then you would need to do that in wpadverts/templates/list-item.php file.

    To avoid having the changes made there overwritten on WPAdverts update consider creating a child template for list-item.php as explained here https://wpadverts.com/documentation/child-themes-and-templates/

    Thread Starter rancidbutcher76

    (@rancidbutcher76)

    Hi Greg,

    Thanks for the quick reply.

    The URL field was added using the custom fields extension.

    Thanks!

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    for fields created with Custom Fields extension, right now the only way to do that would be to open file wpadverts-custom-fields/wpadverts-custom-fields.php and on line about 900 replace

    
    $data[] = sprintf( '<a href="%s">%s</a>', esc_html( $value ), esc_html( $value ) );
    

    with

    
    $data[] = sprintf( '<a href="%s" target="_blank">%s</a>', esc_html( $value ), esc_html( $value ) );
    

    although note this will affect all the URL fields created using CF extension and this change will be overwritten on CF update.

    Thread Starter rancidbutcher76

    (@rancidbutcher76)

    Thanks Greg,

    Will try out both and let you know how i get one.

    Thread Starter rancidbutcher76

    (@rancidbutcher76)

    Hi Greg

    Thanks for the help, the _blank solution worked fine. I do have a quick further question regarding the adverts_list_after_title.

    Searching the code I can see that it’s present in three files and appears to be defined in the mark as sold plugin – class-wpadverts-mas-frontend.php.

    I don’t want to just update it there though as obviously it’ll only appear when it’s marked as sold. Can you tell me where I should add the action you outline? I mean which file.

    Thanks!

    add_action( “adverts_list_after_title”, function( $post_id ) {
    echo ‘‘ . get_post_meta( $post_id, ‘retailer_name’, true ) . ‘‘;
    } );

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    it is best to add it either in your theme functions.php file (usually at the end of the file) or even better create a new WP plugin and paste the code there.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘URL to Open on New Page and User on Adverts’ is closed to new replies.