ThemeShaper Forums » Thematic

replacing filters - thematic_postheader

(5 posts)
  • Started 14 years ago by tripper54
  • Latest reply from Chris
  • This topic is resolved
  1. Hi there,

    I'm new to thematic and wordpress, amazed so far at how much I can do easily. But I'm stuck on this one.

    I would like site authors to be able to specify an author name for a post other than themselves or another registered user. This name would show up in the post header instead of their username.

    I figure the best way to do this is create a custom field "articleauthor" and rewrite the thematic_postheader filter to show the contents of this fielf if it is set, otherwise show the usual username. Pretty simple php.

    I followed the tutorial at http://themeshaper.com/filters-wordpress-child-themes/ and got the postheader to say "bacon". I figured from there all I would have to do is copy and paste the contents of function thematic_postheader() over the echo "bacon"; line in my functions.php, then make the required changes to the code.

    When I do this, the postheader dissappears entirely (after just a straight copy and paste, before changing any code). Here is the function as it sits in my functions.php:

    function childtheme_postheader() {
    
    global $id, $post, $authordata;
    
        // Create $posteditlink
        $posteditlink .= '<a href="' . get_bloginfo('wpurl') . '/wp-admin/post.php?action=edit&post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '';
        $posteditlink = apply_filters('thematic_postheader_posteditlink',$posteditlink); 
    
        if (is_single() || is_page()) {
            $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
        } elseif (is_404()) {
            $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
            $posttitle = '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</h2>\n";
        }
        $posttitle = apply_filters('thematic_postheader_posttitle',$posttitle); 
    
        $postmeta = '<div class="entry-meta">';
        $postmeta .= '<span class="meta-prep meta-prep-author">' . __('By ', 'thematic') . '</span>';
        $postmeta .= '<span class="author vcard">'. '<a class="url fn n" href="';
        $postmeta .= get_author_link(false, $authordata->ID, $authordata->user_nicename);
        $postmeta .= '" title="' . __('View all posts by ', 'thematic') . get_the_author() . '">';
        $postmeta .= get_the_author();
        $postmeta .= '</span><span class="meta-sep meta-sep-entry-date"> | </span>';
        $postmeta .= '<span class="meta-prep meta-prep-entry-date">' . __('Published: ', 'thematic') . '</span>';
        $postmeta .= '<span class="entry-date"><abbr class="published" title="';
        $postmeta .= get_the_time(thematic_time_title()) . '">';
        $postmeta .= get_the_time(thematic_time_display());
        $postmeta .= '</abbr></span>';
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postmeta .= ' <span class="meta-sep meta-sep-edit">|</span> ' . '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
        $postmeta = apply_filters('thematic_postheader_postmeta',$postmeta); 
    
        if ($post->post_type == 'page' || is_404()) {
            $postheader = $posttitle;
        } else {
            $postheader = $posttitle . $postmeta;
        }
    
    }
    add_filter('thematic_postheader','childtheme_postheader');

    What am I doing wrong here?

    thanks

    Posted 14 years ago #
  2. Try adding return $postheader; at the end of th function.

    Posted 14 years ago #
  3. Yet another fight with a two-handed sword :)

    Ok .. let's learn how to fight with a rapier .. take a look at the the code above and search for the author stuff.

    Right .. it is used in $postmeta which has its own filter 'thematic_postheader_postmeta'

    Let me ask a question before I post some code:

    What should happen with the author link??

    Chris

    Posted 14 years ago #
  4. Thanks for the tips - here's my working code:

    function childtheme_postmeta() {
    
    global $id, $post, $authordata;
    
        $postmeta = '<div class="entry-meta">';
        $postmeta .= '<span class="meta-prep meta-prep-author">' . __('By ', 'thematic') . '</span>';
    	//this is the bit I'm changing - override author if the custom field is set
    	$articleauthor = get_post_meta($post->ID, 'articleauthor', true);
    
    	if ($articleauthor) {
    		$postmeta .= '<span class="author vcard">';
    		$postmeta .= $articleauthor;
    		$postmeta .= '</span>';
    
    	} else {
        	$postmeta .= '<span class="author vcard">'. '<a class="url fn n" href="';
        	$postmeta .= get_author_link(false, $authordata->ID, $authordata->user_nicename);
        	$postmeta .= '" title="' . __('View all posts by ', 'thematic') . get_the_author() . '">';
        	$postmeta .= get_the_author();
    	}
        $postmeta .= '</a></span><span class="meta-sep meta-sep-entry-date"> | </span>';
        $postmeta .= '<span class="meta-prep meta-prep-entry-date">' . __('Published: ', 'thematic') . '</span>';
        $postmeta .= '<span class="entry-date"><abbr class="published" title="';
        $postmeta .= get_the_time(thematic_time_title()) . '">';
        $postmeta .= get_the_time(thematic_time_display());
        $postmeta .= '</abbr></span>';
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postmeta .= ' <span class="meta-sep meta-sep-edit">|</span> ' . '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
    
    	//$postmeta = apply_filters('thematic_postheader_postmeta',$postmeta); 
    
    	//actually output this stuff
    	return $postmeta;
    
    }
    add_filter('thematic_postheader_postmeta','childtheme_postmeta');
    Posted 14 years ago #
  5. Looks good.

    Chris

    Posted 14 years ago #

RSS feed for this topic

Reply

You must log in to post.