WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I change "posted on date by " using the new Twenty Ten theme? (16 posts)

  1. Tara
    Member
    Posted 4 years ago #

    how all,

    I am working with the default twentyten theme.

    How can I change "Posted on date, 2010 by admin" and
    "Posted in Category | Tagged | Comments"

  2. MichaelH
    Member
    Posted 4 years ago #

    Need to change the wp-content/themes/twentyten/loop.php (in the area of line 145) and functions.php (in the area of line 500).

    Also might consider using Child Theme to 'protect' yourself from future upgrades.

  3. MichaelH
    Member
    Posted 4 years ago #

    Just for fun, using Aaron Jorbin's examples (see link at bottom of Child Themes), I created a child theme of twentyten, and in the functions.php file of that child theme put this:

    class Thirty_Ten_Text_Wrangler {
    
     function loop_utility_category_meta($translation, $text, $domain) {
      $translations = &get_translations_for_domain( $domain );
      // With Tags
      if ( $text == '<span class="%1$s">Posted in</span> %2$s' ) {
       return $translations->translate( '<span class="%1$s">Posted in t-p requested</span> %2$s' );
      }
      return $translation;
     }
    
    }
    add_filter('gettext', array('Thirty_Ten_Text_Wrangler', 'loop_utility_category_meta'), 10, 4);
    
    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted t-p requested</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( get_the_author_meta( 'ID' ) ),
    			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			get_the_author()
    		)
    	);
    }
  4. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,
    I appreciate your time and guidance.

    I will try your suggestions.

  5. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,
    excellent instructions! Got it working.

  6. Tara
    Member
    Posted 4 years ago #

    Hi MichaelH,
    The changes I made work fine, but they generated buch of validation errors.

    in loop.php, I striked out "posted in" and "tagged"
    and in functions.php,I tried to use get_the_author_link so link directs to the author's website instead of his posts.

    As I said all this works fine but does not pass validation test.

    What would be the valid way to accomplish what I am trying do? I remember in 2.92 it was relatively easy to do this!

    Thanks again.

  7. MichaelH
    Member
    Posted 4 years ago #

    Twenty Ten with the changes I mentioned passed validation for me at http://validator.w3.org

  8. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,

    I am sure i am doing it right.

    Please tell me how to change the author in "posted by AUTHOR"
    That is when I click on "Author" it takes me to the author's webpage instead of his list of posts ("view all post by author"), which is the default.

    You mentioned about line 500 in functions.php. I am not sure what to do there. That may be the reason for my w3 validation problem.

    Thanks.

  9. MichaelH
    Member
    Posted 4 years ago #

    This is all I did.

    Create child theme folder with the proper style.css

    and the functions.php

    <?php
    class Thirty_Ten_Text_Wrangler {
    
     function loop_utility_category_meta($translation, $text, $domain) {
      $translations = &get_translations_for_domain( $domain );
      // With Tags
      if ( $text == '<span class="%1$s">Posted in</span> %2$s' ) {
       return $translations->translate( '<span class="%1$s">Posted in or about</span> %2$s' );
      }
      return $translation;
     }
    
    }
    add_filter('gettext', array('Thirty_Ten_Text_Wrangler', 'loop_utility_category_meta'), 10, 4);
    
    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted odadfadfn</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_the_author_meta( 'URL'),
    			sprintf( esc_attr__( 'See author website %s', 'twentyten' ), get_the_author_meta( 'URL') ),
    			get_the_author()
    		)
    	);
    }
  10. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,

    I have saved the twentyten theme with my modifications as "mytwentyten".
    So it has all the twentyten files including the style.css and functions.php.

    Question: where would I be placing your code in mytwentyten functions.php file?

    The existing functions.php is quite long and I want to make sure I place your code at the right place in it.

    Thanks again for your help and patient.

  11. MichaelH
    Member
    Posted 4 years ago #

    That code I put above would be the ONLY thing in your mytwentyten functions.php file.

    The nature of Child Themes means WordPress will use your child themes functions.php and the 'parent' functions.php also. But the function twentyten_posted_on() if the child theme will be used in place of the that function in the parent theme.

  12. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,

    I created a functions.php with your code (only) and uploaded it (i.e., which overwrote the existing functions.php in "mytwentyten"). Now, instead of the blog, I get this message:

    Fatal error: Call to undefined function: twentyten_posted_on() in /home/XXX../testblog/wp-content/themes/mytwentyten/loop.php on line 128

    What I have done wrong?

    Thanks.

  13. MichaelH
    Member
    Posted 4 years ago #

    Sorry I missed what you said earlier. My child theme only has functions.php (with the code above) and style.css. Please see the Child Themes article for info on the style.css structure.

  14. Tara
    Member
    Posted 4 years ago #

    Thanks MichaelH,

    Thanks for pointing me in the right direction. I read afew times all the material you suggested in your replies, I think I am begining to see a bit as to what's going on. Thanks for your patient.

    If, I may ask, which file i need to tweak to make changes related to the comments box? I went through each twentyten file but i just cannot find.

  15. moylan0
    Member
    Posted 3 years ago #

    Its probably all too late and my thunder is blown. All the suggested modification code and child themes appears to be unneccessary. there is a tinybug in the php call for the div id "meta-prep meta-prep-author" in the loop for twentyten. This is a div id with a space in it. Remove the space between "prep" and "meta" in the function.php.

  16. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    i beg to differ:
    the code is correct; it is a combination of two css classes for a span with the text 'Posted on'

    the code from functions.php:

    printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s"....

    both css classes are not used in Twenty Ten.
    even if it may not make much sense to add two css classes to one span, the code stays correct.

Topic Closed

This topic has been closed to new replies.

About this Topic