• Resolved Iurie Malai

    (@flegmatiq)


    Greg, the ‘Search’ and ‘Location’ fields on adverts lists are displayed only by the list.php template? … that is included by adverts/includes/shortcodes.php shortcodes_adverts_list()? I supose the answer is ‘yes’.

    I needed to customize the list.php template, so I created an own plugin that overrides the original shortcodes_adverts_list():

    add_action( 'wp_loaded', 'override_adverts_list_shortcode' );
    
    function override_adverts_list_shortcode() {
       remove_shortcode( 'adverts_list' );
       add_shortcode( 'adverts_list', 'custom_shortcode_adverts_list' );
    }

    then I copied the original code to the new function and just changed this:

    // adverts/templates/list.php
    ob_start();
    include_once ADVERTS_PATH . 'templates/list.php';
    return ob_get_clean();

    to this:

    // adverts/templates/list.php
    ob_start();
    include_once( plugin_dir_path( __FILE__ ) . '/templates/list.php');
    return ob_get_clean();

    so the WP Adverts now loads my customized list.php template.

    What was customized at this moment I described partially here and this is related to my question. The problem is that this customization works only on the main adverts list page, but not on adverts lists for separate categories – see this (main adverts list) and see this (a category adverts list)). It seems that when a category adverts list page is loaded is used the original shortcodes_adverts_list() and, respectively, the original list.php template, not that I customized. What I am doing wrong here? Can you suggest the right direction of solving this?

    Regards,
    Iurie

    https://www.ads-software.com/plugins/wpadverts/

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

    (@gwin)

    1. In wpadverts/includes/functions.php see function adverts_the_content() it is used when browsing by category and when viewing single ad details.
    2. You will need to unregister it and replace with your own function

    add_action("init", "my_the_content_filters", 200);
    function my_the_content_filters() {
        remove_filter('the_content', 'adverts_the_content');
        add_filter('the_content', 'my_adverts_the_content');
    }

    this should remove adverts_the_content() filter and register my_adverts_the_content() function, which you need to write.

    Thread Starter Iurie Malai

    (@flegmatiq)

    Thank you, Greg! This is resolved. But I discovered a new and interesting issue: I added excerpts to items with get_the_excerpt() and this works well on main adverts list, but doesn’t when browsing by category. More precisely, when browsing by category nothing is displayed, excepting menus (see this). I don’t know if this is related to WP Adverts, but maybe you have an idea what happens.

    This is how looks the mine customized list-item.php:

    <div class="advert-item">
    
        <?php $image = custom_adverts_get_main_image( get_the_ID() ) ?>
        <?php if($image): ?>
            <img src="<?php esc_attr_e($image) ?>" alt="" class="advert-item-grow alignleft" />
        <?php else: ?>
            <img src="" alt="" class="placeholder alignleft" />
        <?php endif; ?>
    
        <h2 title="<?php esc_attr_e( get_the_title() ) ?>" class="advert-link"><?php the_title() ?></h2>
        <a href="<?php the_permalink() ?>" title="<?php esc_attr_e( get_the_title() ) ?>" class="advert-link-wrap"></a>
        <span class="advert-excerpt">txt<?php echo(get_the_excerpt()); ?></span>
    
        <span class="advert-date"><?php echo date_i18n( get_option( 'date_format' ), get_post_time( 'U', false, get_the_ID() ) ) ?></span>
        <?php $price = get_post_meta( get_the_ID(), "adverts_price", true ) ?>
        <?php if( $price ): ?>
            <span class="advert-price"><?php esc_html_e( adverts_price( get_post_meta( get_the_ID(), "adverts_price", true ) ) ) ?></span>
        <?php endif; ?>
    
    </div>
    Thread Starter Iurie Malai

    (@flegmatiq)

    The same story with the_excerpt().

    Thread Starter Iurie Malai

    (@flegmatiq)

    Probably I am wrong, but: can the adverts_the_content() function influence the excerpt when browsing by category? I do not understand fully how it works in the category related part.

    Thread Starter Iurie Malai

    (@flegmatiq)

    Greg, today I disabled all my plugins, excepting WP Adverts, and all my custom functions and I added to the original list-item.php template the next piece of code:

    <span class="advert-excerpt">
        <?php echo get_the_excerpt(); ?>
    </span>

    After this on the main adverts list page excerpts are displayed, but when I open a category page with adverts list excerpts are not displayed. How to repair this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘About the shortcodes_adverts_list() function’ is closed to new replies.