Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1140975
    Lely
    Moderator

    Hello Eric,

    That error means you’ve mostly closed a code block too early. I tried the code on my test site and then there’s no error. Would you mind giving us a copy of your functions.php where those code have been added so we can check?

    #1140981
    Eric
    Participant
    This reply has been marked as private.
    #1140982
    Eric
    Participant
    This reply has been marked as private.
    #1140985
    Eric
    Participant

    I should also mention that I’m currently applying an ‘all’ category to all of my posts, which was done so that all of my posts would appear on the index page. I assume that won’t change anything but I figured I should mention that just in case.

    So anyway let me know if you have any solutions, and thanks again for all your help!

    #1141011
    Paul R
    Moderator

    Hi,

    Please replace the entire code in your functions.php file with this.

    
    <?php
    
    // =============================================================================
    // FUNCTIONS.PHP
    // —————————————————————————–
    // Overwrite or add your own custom functions to X in this file.
    // =============================================================================
    
    // =============================================================================
    // TABLE OF CONTENTS
    // —————————————————————————–
    // 01. Enqueue Parent Stylesheet
    // 02. Additional Functions
    // =============================================================================
    
    // Enqueue Parent Stylesheet
    // =============================================================================
    
    add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );
    
    // Additional Functions
    // =============================================================================
    
    // Add Social Sharing after the single post content
    // =============================================================================
    
    function x_add_social_sharing ( $content ) {
        if ( is_singular('post') ) {
            echo do_shortcode('[share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
        }
    }
    add_action('x_before_the_content_end', 'x_add_social_sharing');
    
    // =============================================================================
    // Translate strings using 'gettext' filter hook.
    // =============================================================================
    
    add_filter('gettext', 'custom_strings_translation', 20, 3);
    
    function custom_strings_translation( $translated_text, $text, $domain ) {
    
    switch ( $translated_text ) {
        case 'Filter by Category' :
        $translated_text = __( 'Filter by Genre', '__x__' );
        break;
    }
    
    return $translated_text;
    }
    
    /** Defer Parsing Of JavaScript*/
    if (!(is_admin() )) {
        function defer_parsing_of_js ( $url ) {
            if ( FALSE === strpos( $url, '.js' ) ) return $url;
            if ( strpos( $url, 'jquery.js' ) ) return $url;
            // return "$url' defer ";
            return "$url' defer onload='";
        }
        add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
    }
    
    function my_custom_footer_output() {
    if (is_single($post)) : ?>
        <script type="text/javascript">
        jQuery( document ).ready(function($) {
            $(".post .entry-header").insertBefore(".post .entry-thumb");
            $(".post .entry-header" ).addClass( "mvl" );
        });
        </script>
    <?php endif; }
    add_action( 'wp_footer', 'my_custom_footer_output', 30 ); ?>
    
    <?php
     function x_entry_navigation() {
    
      $stack = x_get_stack();
    
      if ( $stack == 'ethos' ) {
        $left_icon  = '<i class="x-icon-chevron-left" data-x-icon=""></i>';
        $right_icon = '<i class="x-icon-chevron-right" data-x-icon=""></i>';
      } else {
        $left_icon  = '<i class="x-icon-arrow-left" data-x-icon=""></i>';
        $right_icon = '<i class="x-icon-arrow-right" data-x-icon=""></i>';
      }
    
      $is_ltr    = ! is_rtl();
      $prev_post = get_adjacent_post( true, '', false, 'category' );
      $next_post = get_adjacent_post( true, '', true, 'category' );
      $prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
      $next_icon = ( $is_ltr ) ? $right_icon : $left_icon;
    
      ?>
    
      <div class="x-nav-articles">
    
        <?php if ( $prev_post ) : ?>
          <a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
            <?php echo $prev_icon; ?>
          </a>
        <?php endif; ?>
    
        <?php if ( $next_post ) : ?>
          <a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
            <?php echo $next_icon; ?>
          </a>
        <?php endif; ?>
    
      </div>
    
      <?php
    
      }
    
    

    Hope that helps.

    #1141034
    Eric
    Participant

    Hey so the file was edited successfully, meaning that it didn’t crash my site. However even with the new code, the Prev/Next text still doesn’t show up and the arrows are still being applied to all posts as opposed to the other individual categories. So perhaps there’s something else I need to add on top of that?

    Thanks for the quick reply

    #1141051
    Rue Nel
    Moderator
    This reply has been marked as private.
    #1141057
    Eric
    Participant
    This reply has been marked as private.
    #1141087
    Rue Nel
    Moderator

    Hello There,

    Thanks for the clarifications!

    1&2] To add some text above the Prev/Next in the navigation, and that the post should be in the same terms upon clicking the navigation arrows, please update the code and use this instead:

    <?php
    
    function x_entry_navigation() {
    
      $stack = x_get_stack();
    
      if ( $stack == 'ethos' ) {
        $left_icon  = '<i class="x-icon-chevron-left" data-x-icon=""></i>';
        $right_icon = '<i class="x-icon-chevron-right" data-x-icon=""></i>';
      } else {
        $left_icon  = '<i class="x-icon-arrow-left" data-x-icon=""></i>';
        $right_icon = '<i class="x-icon-arrow-right" data-x-icon=""></i>';
      }
    
      $is_ltr    = ! is_rtl();
      $prev_post = get_adjacent_post( true, '', false );
      $next_post = get_adjacent_post( true, '', true );
      $prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
      $next_icon = ( $is_ltr ) ? $right_icon : $left_icon;
    
      ?>
    
      <div class="x-nav-articles">
    
        <?php if ( $prev_post ) : ?>
          <a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
            <span class="x-nav-text">Previous</span><br/>
            <?php echo $prev_icon; ?>
          </a>
        <?php endif; ?>
    
        <?php if ( $next_post ) : ?>
          <a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
            <span class="x-nav-text">Next</span><br/>
            <?php echo $next_icon; ?>
          </a>
        <?php endif; ?>
    
      </div>
    
      <?php
    
    }

    Please let us know if this works out for you.

    #1141449
    Eric
    Participant

    Hey so the update to my code didn’t really work. Although it did add the text ‘previous’ and next’, it added them to the actual buttons (see screenshot 1), which doesn’t really work with the buttons that small. Again if possible I’d like for the text to be above the buttons just like it is with the ‘share this post’ text (see screenshot 2). The text itself shouldn’t have to be clickable, it just needs to say ‘Prev/Next’ in basic text just above the arrows.

    Also right now when you click on the left arrow, which currently has the word ‘previous’ on it, it jumps to the newer posts, so unfortunately it’s working backwards. So is there anyway to flip the functionality so that the left arrow clicks to the older posts and the right arrow clicks to the newer posts.

    Let me know and thank you once again

    #1142481
    Lely
    Moderator

    Hello Eric,

    Please remove the following part from the previous suggested code:
    <span class="x-nav-text">Previous</span><br/>
    and this:
    <span class="x-nav-text">Next</span><br/>

    Then add the following CSS:

    .x-nav-articles .prev,
    .x-nav-articles .next{
        position: relative;
        margin-top: 20px;
    }
    .x-nav-articles .prev:before {
        content: 'Previous';
        position: absolute;
        top: -30px;
        right: 0;
        font-size: 15px;
        color: rgb(196,166,68);
        cursor: default;
    }
    
    .x-nav-articles .next:before {
        content: 'Next';
        position: absolute;
        top: -30px;
        left: 0;
        font-size: 15px;
        color: rgb(196,166,68);
        cursor: default;
    }
    
    

    See attachment for the result.
    Regarding the order, I did check it and notice that those two post have the same published date and time.

    #1142567
    Eric
    Participant

    Hey thanks! I made some slight adjustments to the code you gave me and now it looks perfect.

    However regarding the order, I just updated the published dates and it’s still backwards. Right now when I click on the newest post, the ‘next button shows up’ and if I click it it moves through the older posts (and similarly if I go to the oldest post the ‘previous’ button shows up and if I click it, it moves to a newer post). So could I somehow reverse that? Ideally I’d like the ‘previous’ button to click through the older posts, with the ‘next’ button clicking through the newer posts.

    #1142929
    Lely
    Moderator

    Hello Eric,

    Can you try updating this part of the code :

      $prev_post = get_adjacent_post( true, '', false );
      $next_post = get_adjacent_post( true, '', true );
    
    

    To this:

      $prev_post = get_adjacent_post( true, '', true);
      $next_post = get_adjacent_post( true, '', false);
    
    

    Hope this helps.

    #1143005
    Eric
    Participant

    Worked perfectly! Thanks for all your help. Very much appreciated

    #1143257
    Joao
    Moderator

    Glad to hear we managed to help.

  • <script> jQuery(function($){ $("#no-reply-1138462 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>