Creating functions.php in child theme

i want to make some modifications to one of the functions in the Twenty Ten functions.php file. so i added a functions.php file (see code below) to my child folder. but now my site doesnt work.

I get an error message that says "“Parse error: syntax error, unexpected T_ENDIF in /home/content/p/o/o/html/green/wordpress/wp-content/themes/twentytenchild/functions.php on line 48”. Any idea what’s wrong???


<?php

/** Tell WordPress to run child_theme_setup()
when the 'after_setup_theme' hook is run.
*/
add_action( 'after_setup_theme', 'child_theme_setup' );

/** This function will hold our new calls and over-rides */
if ( !function_exists( 'child_theme_setup' ) ):
function child_theme_setup() {

    /*
    I want the Posted On date to show, but not the author.
    */

function twentyten_posted_on() {

        printf( __( '<span class="%1$s">Posted on</span> %2$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()

                )

        );

}
endif; ?>

so in a different forum, someone helped me create the following code in my child folder’s function.php file, which did the trick:


<?php
add_action( 'after_setup_theme', 'child_theme_setup' );

/** This function will hold our new calls and over-rides */
if ( !function_exists( 'child_theme_setup' ) ):
function child_theme_setup() {
	
	/* 
	We want a Second Navigation Bar right at the top 
	This theme uses wp_nav_menu() in two locations.
	*/
	register_nav_menus( array(
		'secondary' => __( 'Top Navigation', 'twentyten' ),
	) );

}
endif;


/* We want the Posted On date to show, but not the author. */
function twentyten_posted_on() {
	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep"></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('')
	);
}

but now i have a similar functionality that I want to get cleared up, but am unable to figure out how to do so. on the category pages of the site (example: http://greenrefurbishing.com/wordpress/category/coupons/), below the excerpt it shows Posted In: Category XYZ | Leave a comment. I want to remove everything after Category XYZ, in red above.

But in this instance, the code that creates this functionality, as far as i can tell, is found in lines 157-161 of the loop.php file of the parent folder.


					<span class="meta-sep">|</span>
				<?php endif; ?>
				<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
				<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
			</div><!-- .entry-utility -->

so in this instance, do i also add something to the child’s functions.php file to cancel out this function???

and this is what I would put in the child folder’s functions.php file? or the parent folder’s? i want to make sure any changes i make are just to the child folder files so that my theme will be protected against updates to the Twenty Ten parent theme.

please advise. thanks!

Not the best, but you could hack the function

function twentyten_posted_on() {
	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" 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()
		)
	);
}

With the nested "print"s its a bit confusing, but of you break it down

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

is the resulting output.
%1$s = ‘meta-prep meta-prep-author’ - the span Id, should be OK as is.

%2$s = 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()
), - the linked date/time, you still want that.

%3$s = 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()
) - the “by” stuff you dont want.

So you could simply comment that out and change the main print

function twentyten_posted_on() {
//	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
	printf( __( '<span class="%1$s">Posted on</span> %2$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()
		)
	);
}

so the last two lines need to look like this?


}}
endif; ?>

or do i put that closing bracket } right before the second mention of “function”?

I don’t know, it depends. Do you want the second function to be inside the first?


function child_theme_setup() {


function twentyten_posted_on() {

You open two functions, but there’s only one closing bracket at the end.

What I posted was a hack of the original function, whatever folder that’s in.

If it’s in the parent theme’s files, then yes, hacking it will present a maintenance task everytime the theme updates - not optimal.

I’m not sure if putting a function of the same name in the child’s function file would work. I think so, but AFAIK the correct way is to “hook” it to the parent’s function.

Let me re-read that part of the book and I’ll post back ASAP.

ummm, not really sure.

basically i’m just trying to modify the original function where, beneath the post titles, it spits out “Posted on 1/1/2010 by John Doe” and create a function where it just says “Posted on 1/1/2010” without the author name.

any advice?