Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #19781
    Angela B
    Participant

    Good evening,

    Re http://theme.co/x/member/forums/topic/change-blog-date-display/

    Based on the ticket above, I have created a directory in my child theme into which I have copied renew.php from the parent theme:
    From:
    /wp-content/themes/x/framework/functions/renew.php
    To:
    /wp-content/themes/x-child-renew/framework/functions/renew.php

    When I make a small modification, such as to change the date format on blog posts, the child theme renew.php is not being recognised; I still get the default format of ‘m.Y’.
    However, when I update the parent theme renew.php with the same changes (I want to see d.m.Y), the changes are applied.

    I am sure that I have followed all instructions to get the child theme to work correctly…does the above sound like I have missed a step?

    Thanks in advance,
    Angela

    #19892
    Kory
    Keymaster

    Hey Angela,

    Thanks for writing in! When you are making updates to your theme, all functions can be overwritten in the functions.php file of the child theme as long as the name of the function matches the name of the function you’re trying to overwrite exactly and that this same function is also wrapped in a function_exists statement. For example, if there is a function located anywhere in the parent theme somewhere that looks like this:

    if ( ! function_exists( 'x_do_stuff' ) ) :
      function x_do_stuff() {
        ...do stuff...
      }
    endif;

    You can overwrite it in your child theme by simply doing something like the following in the functions.php file of your child theme:

    x_do_stuff() {
      ...do something different...
    }

    The only time that you will copy over files to overwrite them is when you’re wanting to overwrite a template or View in X. There is extensive documentation on this in our Knowledge Base that goes over this in much greater detail than I can provide here and you will want to review this if you haven’t done so already.

    You’re in the right mindset for what you’re trying to do, but the implementation is a little bit off. Hopefully the information above makes it clear on what you’re to do now.

    Thanks!

    #20095
    Angela B
    Participant

    Perfect, thank you so much!

    I have simply copied the function in from the parent renew.php functions file to the functions.php file in my child theme and then made my changes to the date format from there.

    I feel like I keep asking simple questions but if you don’t ask you never learn!

    I would also like to say that the support facility for the X theme is absolutely brilliant. Well done! x

    #20305
    Kory
    Keymaster

    Hey Angela,

    We’re so glad to know that things are in order now and incredibly thankful for your very generous words about our support. We continue to strive to provide the best support experience possible and are glad that you have found it to be enjoyable. We look forward to continuing to serve you. 🙂

    #25150
    Helene C
    Participant

    Hi there,

    I believe I’m trying to do what Angela was trying to do — edit the date format. However I’m not meeting with success.

    Here’s the way I’m approaching it, based on my understanding of the above — I’m copying the function x_renew_entry_meta() from the renew.php file and pasting it into my functions.php file like so:

    x_renew_entry_meta() {
    ... 
    $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date( 'F, Y' ) )
        );
    ... }

    But this is white screening. I tried entering it into a plugin I have to keep functions separate (and avoid killing the site when I do something wrong — it just deactivates itself and spits out an error instead) and it tells me that there’s a syntax error in the first line of this function… Parse error: syntax error, unexpected ‘{‘. Not sure what that means in this context..?

    So, I guess I have a couple questions — first, must I replicate the entire function in functions.php? Or can I just override a part of it, e.g. define the $date variable differently?

    If I must replicate the whole thing, can you tell me if there’s anything wrong with the below?

    function x_renew_entry_meta() {
    
        $author = sprintf( '<span>%s</span>',
          get_the_author()
        );
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date( 'F, Y' ) )
        );
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>%s</span>',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '">'
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>%s</span>',
            trim( $categories_output, $separator )
          );
        }
    
        if ( comments_open() ) {
          if ( get_comments_number() == 0 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( get_comments_link() ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), get_the_title() ) ),
              __( 'Leave a Comment' , '__x__' )
            );
          } else if ( get_comments_number() == 1 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( get_comments_link() ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), get_the_title() ) ),
              get_comments_number() . ' ' . __( 'Comment' , '__x__' )
            );
          } else {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( get_comments_link() ),
              esc_attr( sprintf( __( 'View all comments on: &ldquo;%s&rdquo;', '__x__' ), get_the_title() ) ),
              get_comments_number() . ' ' . __( 'Comments' , '__x__' )
            );
          }
        } else {
          $comments = '';
        }
    
        $post_type           = get_post_type();
        $post_type_post      = $post_type == 'post';
        $post_type_portfolio = $post_type == 'x-portfolio';
        $no_post_meta        = get_theme_mod( 'x_blog_enable_post_meta' ) == 0;
        $no_portfolio_meta   = get_theme_mod( 'x_portfolio_enable_post_meta' ) == 0;
    
        if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $author,
            $date,
            $categories_list,
            $comments
          );
        }

    Thank you, as always!

    #25422
    Kory
    Keymaster

    Hey Helene,

    Thanks for writing in! Whenever copying over a function to your functions.php file in your child theme, you must always copy the entire function, never just a portion of it as this will create an error on your site most likely. I don’t see any errors off the top of my head scanning what you’ve pasted above, so you should be good to go.

    Thanks!

    #26205
    Helene C
    Participant

    Hi there,

    As mentioned, unfortunately the above causes the ol’ white screen of death. So there’s definitely something I’m doing wrong. All the other functions I’ve been adding work fine.

    Do you have any idea what might be up?

    Thanks!
    -H

    #26701
    Kory
    Keymaster

    Hey Helene,

    Thanks for writing in! You appear to be missing a closing curly brace (}) at the end of your file. Adding this should remedy the problem.

    Thanks!

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