SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    May 2010
    Posts
    229
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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_attrget_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_urlget_the_author_meta'ID' ) ),

                            
    sprintfesc_attr__'View all posts by %s''twentyten' ), get_the_author() ),

                            
    get_the_author()

                    )

            );

    }
    endif; 
    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code PHP:
    function child_theme_setup() {
     
     
    function twentyten_posted_on() {
    You open two functions, but there's only one closing bracket at the end.

  3. #3
    SitePoint Addict
    Join Date
    May 2010
    Posts
    229
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    so the last two lines need to look like this?

    PHP Code:
    }}
    endif; 
    ?> 
    or do i put that closing bracket } right before the second mention of "function"?
    Last edited by sixrfan; Sep 13, 2010 at 07:49. Reason: expanded thought

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I don't know, it depends. Do you want the second function to be inside the first?

  5. #5
    SitePoint Addict
    Join Date
    May 2010
    Posts
    229
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Not the best, but you could hack the function
    Code PHP:
    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
    PHP Code:
    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
    Code PHP:
    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()
    		)
    	);
    }

  7. #7
    SitePoint Addict
    Join Date
    May 2010
    Posts
    229
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    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.

  9. #9
    SitePoint Addict
    Join Date
    May 2010
    Posts
    229
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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_attrget_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/wordpre...egory/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.

    PHP Code:
                        <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???


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •