WordPress.org

Forums

[resolved] how to add post entry meta just below post title in twenty twelve child (14 posts)

  1. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hellow,

    i want to add AUTHOR NAME,DATE,CATEGARY in twentytwelvechild.
    i used some code in INDEX.PHP file,but no use.

    below is code i added:

    ` <p class="post-info"> by <a href="<?php echo get_author_posts_url(get_the_author_meta
    ('ID')); ?>"><?php the_author(); ?> | on <?php the_time('F jS, y'); ?> | posted in
    <?php

    $categories = get_the_category();
    $separator = ", ";
    $output = '';

    if ($categories) {
    foreach ($categories as $category) {

    $output .= 'term_id) . '">' . $category->cat_name . $separator;
    }
    echo trim($output, $separator);
    }
    ?>

    </p>

    HELP IS REALLY APPRICIATED.

    http://myfreelancelifestyle.com

  2. Kidcompassion
    Member
    Posted 11 months ago #

    My first guess is that maybe you aren't adding it inside the loop? It looks like it should work at first glance. What happened when you added it?

  3. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    nothing changed

  4. Kidcompassion
    Member
    Posted 11 months ago #

    that's actually good! if you didn't get any errors, then your code is probably good.

    i don't how familiar you are with wordpress, but you need to get your code inside the loop, or it won't work:

    http://codex.wordpress.org/The_Loop

    If you don't know, the loop is the part of your code that looks like this:

    <?php
    if ( have_posts() ) {
    	while ( have_posts() ) {
    		the_post(); ?>
    		// here's where your code would go
    		<p class="post-info"> by <a href="<?php echo get_author_posts_url(get_the_author_meta
    ('ID')); ?>"><?php the_author(); ?> | on <?php the_time('F jS, y'); ?> | posted in
    <?php
    
    $categories = get_the_category();
    $separator = ", ";
    $output = '';
    
    if ($categories) {
    foreach ($categories as $category) {
    
    	$output .= 'term_id) . '">' . $category->cat_name . $separator;
    	}
    echo trim($output, $separator);
    }
    ?>
    
    </p>
    		//
    	<?php } // end while
    } // end if
    ?>

    When I debug an issue like this, i start by getting just one piece to work, and then i add the rest a bit at a time so i can tell which part is blowing things up. So maybe try putting just
    <?php the_author(); ?>
    inside the loop and see if you can get it working.

  5. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    this is my index.php file where i added entry meta code.but after updating file,site is not loading:

    <?php
    /**
    * The main template file
    *
    * This is the most generic template file in a WordPress theme
    * and one of the two required files for a theme (the other being style.css).
    * It is used to display a page when nothing more specific matches a query.
    * For example, it puts together the home page when no home.php file exists.
    *
    * @link http://codex.wordpress.org/Template_Hierarchy
    *
    * @package WordPress
    * @subpackage Twenty_Twelve
    * @since Twenty Twelve 1.0
    */

    get_header(); ?>

    <div id="primary" class="site-content">
    <div id="content" role="main">
    <?php if ( have_posts() ) : ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

    <p class="post-info"> by <a href="<?php echo get_author_posts_url(get_the_author_meta
    ('ID')); ?>"><?php the_author(); ?> | on <?php the_time('F jS, y'); ?> | posted in
    <?php

    $categories = get_the_category();
    $separator = ", ";
    $output = '';

    if ($categories) {
    foreach ($categories as $category) {

    $output .= 'term_id) . '">' . $category->cat_name . $separator;
    }
    echo trim($output, $separator);
    }
    ?>

    </p>

    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>

    <?php twentytwelve_content_nav( 'nav-below' ); ?>

    <?php else : ?>

    <article id="post-0" class="post no-results not-found">

    <?php if ( current_user_can( 'edit_posts' ) ) :
    // Show a different message to a logged-in user who can add posts.
    ?>
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
    </header>

    <div class="entry-content">
    <p><?php printf( __( 'Ready to publish your first post? Get started here.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
    </div><!-- .entry-content -->

    <?php else :
    // Show the default message to everyone else.
    ?>
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
    </header>

    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
    <?php get_search_form(); ?>
    </div><!-- .entry-content -->
    <?php endif; // end current_user_can() check ?>

    </article><!-- #post-0 -->

    <?php endif; // end have_posts() check ?>

    </div><!-- #content -->
    </div><!-- #primary -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  6. Kidcompassion
    Member
    Posted 11 months ago #

    It's breaking in this line:

    $output .= 'term_id) . '">' . $category->cat_name . $separator;

    I'm not sure what you're trying to do with term_id, but i took it out and wrote the line as:

    $output = $category->cat_name . $separator;

    and it worked! So maybe double check that you were trying do in that line?

  7. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hey,kidcompassion

    it worked,but it appeared above THE POST TITLE.

    i want it to appear BELOW THE POST TITLE.

    This meta data information appears only in HOME PAGE.

    if i click on particular post,then the post appears in full and there will be no META DATA INFORMATION BELOW POST TITLE.

    what to do. please help me friend.

  8. Kidcompassion
    Member
    Posted 11 months ago #

    AH! I understand!

    Okay: t way this theme works is that in the index.php, it creates a loop, and then it pulls in a content template file instead of the individual functions and logic to show data.

    Normally, a basic theme has an index file, with the loop, and it will say something like:

    <?php
    if ( have_posts() ) {
    	while ( have_posts() ) {
    		the_post();
    		//the_title();
    		// the_content();
    		//blah blah blah
    	} // end while
    } // end if
    ?>

    But when what you want to show for each individual post in the loop is really complex, that requires a lot of code. The best practice for handling that is to include it in a separate file, called a template part (here's some info in the codex: http://codex.wordpress.org/Include_Tags#Custom_Template_files) . That's what's you're currently doing with this line:

    <?php get_template_part( 'content', get_post_format() ); ?>

    So all the stuff you want to edit is actually in THAT template file, which is called content.php. I can't know for sure without seeing everything you have, but I'm pretty sure if you make a copy of their content.php and add it to your child theme, you will be able to edit that file to include your meta data where you want it.

    Let me know if that works!

  9. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hellow,

    here is my content.php file in child:

    [please read http://codex.wordpress.org/Forum_Welcome#Posting_Code for posting code in the forum - the code below might be partially broken]

    <?php
    /**
     * The default template for displaying content
     *
     * Used for both single and index/archive/search.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?>
    
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    		<div class="featured-post">
    			<?php _e( 'Featured post', 'twentytwelve' ); ?>
    		</div>
    		<?php endif; ?>
    		<header class="entry-header">
    			<?php if ( ! post_password_required() && ! is_attachment() ) :
    				the_post_thumbnail();
    			endif; ?>
    
    			<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a>" rel="bookmark"><?php the_title(); ?></a>
    			</h1>
    			<?php endif; // is_single() ?>
    			<?php if ( comments_open() ) : ?>
    				<div class="comments-link">
    					<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
    				</div><!-- .comments-link -->
    			<?php endif; // comments_open() ?>
    		</header><!-- .entry-header -->
    
    		<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    		<?php else : ?>
    		<div class="entry-content">
    			<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>
    
    		<footer class="entry-meta">
    			<?php twentytwelve_entry_meta(); ?>
    			<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
    			<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
    				<div class="author-info">
    					<div class="author-avatar">
    						<?php
    						/** This filter is documented in author.php */
    						$author_bio_avatar_size = apply_filters( 'twentytwelve_author_bio_avatar_size', 68 );
    						echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
    						?>
    					</div><!-- .author-avatar -->
    					<div class="author-description">
    						<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
    						<p><?php the_author_meta( 'description' ); ?></p>
    						<div class="author-link">
    							<a>" rel="author">
    								<?php printf( __( 'View all posts by %s <span class="meta-nav">→</span>', 'twentytwelve' ), get_the_author() ); ?>
    							</a>
    						</div><!-- .author-link	-->
    					</div><!-- .author-description -->
    				</div><!-- .author-info -->
    			<?php endif; ?>
    		</footer><!-- .entry-meta -->
    	</article><!-- #post -->
  10. Kidcompassion
    Member
    Posted 11 months ago #

    Cool! So try adding your code for your desired meta data (minus that one line that was throwing an error) in content.php, under the line with the_title() in it. That should get you closer to what you want.

  11. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hellow,

    i don't know, how to enter code.

    i want:1)author name etc below post title.
    2)author name etc for every full post
    please,help me.

  12. alchymyth
    Forum Moderator
    Posted 11 months ago #

    in content.php in your child theme of Twenty Twelve, add the code for the author meta after this line:

    <?php endif; // is_single() ?>

    for example:

    <?php if( is_single() ) {
    		$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    		get_the_author()
    		);
    		$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() )
    		);
    		$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    		$utility_text = '<span class="entry-meta"><span class="by-author">%3$s</span> %2$s %1$s</span>';
    
    		printf(
    		$utility_text,
    		$categories_list,
    		$date,
    		$author
    		);
    	} ?>

    might need some CSS for better formatting.

  13. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hellow,

    nothing has changed.

    first off,i added some code to index.php file. here is code:

    <p class="post-info"> by <a href="<?php echo get_author_posts_url(get_the_author_meta
    ('ID')); ?>"><?php the_author(); ?> | on <?php the_time('F jS, y'); ?> | posted in
    <?php

    $categories = get_the_category();
    $separator = ", ";
    $output = '';

    if ($categories) {
    foreach ($categories as $category) {

    $output = $category->cat_name . $separator;
    }
    echo trim($output, $separator);
    }
    ?>

    </p>

    but it has appeared above the POST TITLE which i want BELOW THE POST TITLE.
    and i also want it in every full post.

    i tryied alchymyth's code in content.php which has changed nothing. what should i exactly do? please help me.

  14. venkymyfreelancelifestyle
    Member
    Posted 11 months ago #

    hellow,

    i solved my problem.

    thank you madam, and also to sir.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.