[Resolved] Significant changes in single.php (recent update)

Home Forums Support [Resolved] Significant changes in single.php (recent update)

Home Forums Support Significant changes in single.php (recent update)

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1559622
    Gerardo

    Dears,
    In https://sandbox.ital2.org we’re using Heyoya comments area. To do this I needed to insert an extra line of code (a little snippet) into the single.php file.
    Now, I’ve recently updated the version of GP and into the PHP file I can’t find the area where I used to put the Heyoya script.

    Here is how it was (nothing changed up to line 22 [do_action( ‘generate_before_main_content’ );]):


    do_action( ‘generate_before_main_content’ );

    while ( have_posts() ) : the_post();

    get_template_part( ‘content’, ‘single’ );

    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || ‘0’ != get_comments_number() ) :
    /**
    * generate_before_comments_container hook.
    *
    * @since 2.1
    */
    do_action( ‘generate_before_comments_container’ );
    ?>

    <script type=”text/javascript” src=”https://commerce-static.heyoya.com/b2b/b2b_settings.hey?affId=V4DIH0gsTH”></script><hr />
    <?php comments_template(); ?>

    <?php
    endif;

    endwhile;

    /**
    * generate_after_main_content hook.
    *
    * @since 0.1
    */
    do_action( ‘generate_after_main_content’ );
    ?>
    </main><!– #main –>
    <!– #primary –>

    <?php
    /**
    * generate_after_primary_content_area hook.
    *
    * @since 2.0
    */
    do_action( ‘generate_after_primary_content_area’ );

    generate_construct_sidebars();

    get_footer();

    After updating GP what I have is just:


    do_action( ‘generate_before_main_content’ );

    if ( generate_has_default_loop() ) {
    while ( have_posts() ) :

    the_post();

    generate_do_template_part( ‘single’ );

    endwhile;
    }

    /**
    * generate_after_main_content hook.
    *
    * @since 0.1
    */
    do_action( ‘generate_after_main_content’ );
    ?>
    </main>

    <?php
    /**
    * generate_after_primary_content_area hook.
    *
    * @since 2.0
    */
    do_action( ‘generate_after_primary_content_area’ );

    generate_construct_sidebars();

    get_footer();

    So, in the end I went to just before the closing body tag and put the snippet, but the result was very bad.

    This is how the comments area looked before updating (correct):
    the comment area befor updating

    This is how it looks now:
    the comments area now

    Thanks for your attention.

    Best

    #1559709
    Elvin
    Staff
    Customer Support

    Hi,

    By single.php did you mean the default single.php file that comes with the theme?

    If yes, we highly discourage editing of the default PHP files as changes you make will be wiped out when you update the theme.

    You should use a child theme and add in your template pages along with it(ex: single.php, content.php etc) so it doesn’t get overwritten when you update the parent theme.

    But to point you to the difference:

    You’ve replaced the code on the default single.php’s line 29 which is this one:
    generate_do_template_part( 'single' );

    With this one:

    get_template_part( 'content', 'single' );
    
    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || '0' != get_comments_number() ) :
    /**
    * generate_before_comments_container hook.
    *
    * @since 2.1
    */
    do_action( 'generate_before_comments_container' );
    ?>
    
    <script type=”text/javascript” src=”https://commerce-static.heyoya.com/b2b/b2b_settings.hey?affId=V4DIH0gsTH”></script><hr />
    <?php comments_template(); ?>
    
    <?php
    endif;
    #1562290
    Gerardo

    Thank you, Elvin, for your prompt reply.

    First things first: I mean the single.php file that comes with GP.

    What I really did, in the “pre-updated” version of the GP theme, was, right after lines 35 & 36

    do_action( 'generate_before_comments_container' );
    ?>

    and then line 38
    <div class="comments-area">
    to insert the snippet Heyoya provided me with
    <div id="heyoyaDiv"></div><script type="text/javascript" src="https://commerce-static.heyoya.com/b2b/b2b_settings.hey?affId=V4DIH0gsTH"></script>

    Of course it’s a good idea to have a child theme, even though here I had just a little snippet to add. Up to now it has been very easy and fast to manually edit the theme by adding that little piece of code.

    Anyway, my problem, now, with the new version of single.php (of the updated theme), is that I can’t find where to make this editing. This way, I can’t even create the child theme.
    What I dare to insist is the difference between the 2 version of the single.php file. The old one was 65 lines of lenght, while the new one is just 54 lines.

    #1562474
    Elvin
    Staff
    Customer Support

    Anyway, my problem, now, with the new version of single.php (of the updated theme), is that I can’t find where to make this editing. This way, I can’t even create the child theme.

    Again, we don’t recommend editing the default theme files as you’ll end up losing these changes you’re applying once the theme updates again.

    What I dare to insist is the difference between the 2 version of the single.php file. The old one was 65 lines of lenght, while the new one is just 54 lines.

    Here’s the official github page of the theme.
    https://github.com/tomusborne/generatepress/

    Here’s the newest version of the file. (54 lines)
    https://github.com/tomusborne/generatepress/blob/3.0.2/single.php

    Here’s the version w/ the last big change. (67 lines, version 2.4.2, most likely the one you’re using)
    https://github.com/tomusborne/generatepress/blob/2.4.2/single.php

    Lines 29 to 40 of single.php version 2.4.2 are moved to .../generatepress/inc/structure/comments.php which is here: https://github.com/tomusborne/generatepress/blob/e030f57d2c26991074a6868265737424dac567d0/inc/structure/comments.php#L184

    Here’s my recommendation:

    You don’t need to edit any files or create any child themes for this particular one.

    I believe a Hook Element is perfect for this.
    https://docs.generatepress.com/article/hooks-element-overview/

    Place your script on the Hook Element’s code area and set its hook to generate_before_comments_container.

    You then set the display rule to “Post – All Posts”.

    #1595173
    Gerardo

    Hi, thank you for you patience.
    I followed your recommendations, and it seemed easy to do.
    I created a (new) Hook Element, like described in https://docs.generatepress.com/article/hooks-element-overview.
    Then I grabbed the script from Heyoya.com, and pasted it into the text area.
    Finally, I chose “generate_before_comments_container” option (from the drop down menu).
    Nonetheless, I’m facing 2 problems.
    The first, the big one, is that the comment area appears at the very end of each page, I mean, even after the footer (https://sandbox.ital2.org/).
    The second is that even though I set it to appear only on posts (Display Rules: Post => All Posts), the comment area appears, as I mentioned, on each and every page.
    I tried changing the priority (1 to 10) and tweaking around. Nothing changed.
    Maybe there’s something wrong in the script itself?

    <script type=”text/javascript” src=”https://commerce-static.heyoya.com/b2b/b2b_settings.hey?affId=V4DIH0gsTH”></script&gt;

    #1595941
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    If you set the Display Rules, the hook won’t execute elsewhere.

    Do you have any other hooks or custom functions with the same code? Or have you made any other changes to the core theme templates?

    If you add some text to the Hook Element above the script (just the word “hi” or something), does it appear on every single page as well?

    #1596120
    Gerardo

    Sorry, I left the script into the footer.php :/
    Now it’s ok.
    Of course I can read “hi”.
    Thanks

    #1597284
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.