• Resolved Ceyar

    (@ceyar)


    Hello Greg, thank you for the updates.

    I have a problem overriding the templates files. I created the plugin to override files like you do on your github account, and for some files it does work fine but for the single.php it does not work and always use the main template from the wpadverts plugin.

    Any suggestion?

    Thank you in advance.

    https://ww.wp.xz.cn/plugins/wpadverts/

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

    (@gwin)

    Hi, hmm right now you can overwrite this file in three steps:
    1. create a single-advert.php file in your current theme directory
    2. copy to it content from theme single.php file
    3. in the single-advert.php replace the_content() with content from wpadverts/templates/single.php

    I didn’t add overriding functionality to the single.php template file because it is a bit different template (not used by shortcodes), but after all i suppose it does not hurt to have this filter there so i will add it in version 1.0.5.

    Thread Starter Ceyar

    (@ceyar)

    Ah yes great Idea.

    Thank you!

    Ryan

    (@daobydesign)

    Greg, thanks for such an awesome plugin! I saw your other post to Ceyar about how to override the template files, and then found my way here when overriding the single.php file didn’t work.

    I tried the above and had some odd results with a mix of the modified single-advert.php and the original single.php templates. I’m not sure if it is just my site’s configuration (I may be filtering $content elsewhere, I can’t remember off hand).

    However, not able to wait until v1.0.5, I jumped into your source and added the appropriate filter so the single.php override will work. Figured I’d post it here in case anyone else needs the fix before 1.0.5 is released.

    Edit [PLUGIN_FOLDER]/wpadverts/includes/functions.php — replace ln ~351:
    include ADVERTS_PATH . 'templates/single.php';

    With:
    include apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/single.php' );

    Make the same edit to the first line in /templates/add-preview.php (or your overridden version of it).

    Would be great to have that template override function in the main documentation at wpadverts.com. Just putting my +1 on it, no pressure, as I know first-hand the time constraints of plugin management. You’re doing an awesome job though man. Loving this plugin.

    Plugin Author Greg Winiarski

    (@gwin)

    Thanks @ryan, i actually already have this code ready for version 1.0.5, so after upgrading your custom single.php file should be picked up properly.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Overriding single.php template does not work.’ is closed to new replies.