• Resolved F Ran

    (@lobovcf)


    Hi. I love your theme, and I would like to implement it in my collaborative blog, but I have some doubts. How could include, under the title, category and author of each post both on the cover as the post itself?

    Thanks in advance;)

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi there!

    I’m happy to hear you like the look of the theme. 🙂

    Would you like to position the category and author information beneath the title of single posts only? For example, beneath “Road trip” on this post on Boardwalk’s demo site:

    https://boardwalkdemo.wordpress.com/2014/12/20/road-trip/

    Would you also like the information to display beneath the titles on the main posts page? For example, this page on the demo site:

    https://boardwalkdemo.wordpress.com/

    You can make just about any changes you wish to your theme by first creating a child theme and then editing the code from there.

    Let me know the answers to my above questions on what you’re trying to achieve and also give me an idea on your familiarity with HTML, PHP, and CSS. I’ll be happy to guide you from there.

    Thread Starter F Ran

    (@lobovcf)

    Yes, that is, I want to put the author of the post and category under the title on the cover and inside the post. Unfortunately I do not know much about php or html, although I understand CSS something better. In any case if you give me some understandable guides I think I can follow in your footsteps.

    I appreciate it a lot! 😉

    Thread Starter F Ran

    (@lobovcf)

    the cover = main posts page

    Thank you for the extra information! Assuming you’ve already created a child theme:

    The files you need to copy over from your parent theme to your child theme are content-single.php and content.php.

    • content-single.php defines the structure for single posts on your site.
    • content.php defines the structure for the posts page on your site.

    You will find two functions that the theme calls in these files:

    • boardwalk_entry_meta() is used in both files order to output the date above the post’s title.
    • boardwalk_entry_footer() is used in content-single.php in order to output the post’s categories and author information at the bottom of a single post.

    You can find both of the above functions by visiting the parent theme’s inc/template-tags.php file.

    You will need to create a new function in your child theme’s functions.php file that outputs information in a similar way to those two functions.

    Name you function something like boardwalk_child_entry_meta() and then call it in your child theme’s content-single.php and content.php files.

    Let me know how you get on with that!

    Thread Starter F Ran

    (@lobovcf)

    Hello again!

    The truth is I’m not sure to be doing well, sorry for my little knowledge. I copied a new boardwalk_child_entry_meta function in the child theme functions.php like this:

    boardwalk_child_entry_meta function () {
    $ TIME_STRING = '<time class = "entry-date published updated" datetime = "% 1 $ s">% 2 $ s </ time>';
    if (get_the_time ( 'U')! == get_the_modified_time ( 'U')) {
    $ TIME_STRING = '<time class = "entry-date published" datetime = "% 1 $ s">% 2 $ s </ time> <time class = "updated" datetime = "% 3 $ s">% 4 $ s </ time> ';
    }
    
    $ TIME_STRING = sprintf ($ TIME_STRING,
    esc_attr (get_the_date ( 'c')),
    esc_html (get_the_date ()),
    esc_attr (get_the_modified_date ( 'c')),
    esc_html (get_the_modified_date ())
    );
    
    if (is_single ()) {
    $ Posted_on = $ TIME_STRING;
    } Else if (is_sticky () &&! Is_paged ()) {
    $ Posted_on = '<a href="'. Esc_url( boardwalk_get_link_url()).'" Rel="bookmark">'. __ ( 'Featured', 'boardwalk'). '</a>';
    } Else {
    $ Posted_on = '<a href="'. Esc_url( boardwalk_get_link_url()).'" Rel="bookmark">'. $ TIME_STRING. '</a>';
    }
    
    echo '<span class = "posted-on">'. $ Posted_on. '</ Span>';
    }

    The in the child theme new single_content.php I copied this:

    <header class="entry-header">
    		<div class="entry-meta">
    			<?php boardwalk_child_entry_meta(); ?>
    		</div><!-- .entry-meta -->
    		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
    	</header><!-- .entry-header -->

    It is correct?

    Thanks for your patience 😉

    You’re on the right path! 🙂

    So, you’re right to create a new function and to name it boardwalk_child_entry_meta(). We can borrow the following code from boardwalk_entry_footer(), which outputs information the post’s author and categories:

    $categories_list = get_the_category_list( __( ', ', 'boardwalk' ) );
    		if ( $categories_list && boardwalk_categorized_blog() ) {
    			printf( '<span class="cat-links">' . __( 'Posted in %1$s', 'boardwalk' ) . '</span>', $categories_list );
    	}
    
    	if ( 1 != get_theme_mod( 'boardwalk_author_bio' ) ) {
    		$byline = sprintf( '<span class="byline">' . _x( 'By %s', 'post author', 'boardwalk' ) . '</span>', '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>' );
    			echo $byline;
    	}

    Bringing this into your new child theme’s function, this would leave you with:

    if ( ! function_exists( 'boardwalk_child_entry_meta' ) ) :
    /**
     * Prints HTML with meta information for the date.
     */
    function boardwalk_child_entry_meta() {
    
    	$categories_list = get_the_category_list( __( ', ', 'boardwalk' ) );
    		if ( $categories_list && boardwalk_categorized_blog() ) {
    			printf( '<span class="cat-links">' . __( 'Posted in %1$s', 'boardwalk' ) . '</span>', $categories_list );
    	}
    
    	if ( 1 != get_theme_mod( 'boardwalk_author_bio' ) ) {
    		$byline = sprintf( '<span class="byline">' . _x( 'By %s', 'post author', 'boardwalk' ) . '</span>', '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>' );
    			echo $byline;
    	}
    
    	echo '<span class="posted-on">' . $posted_on . '</span>';
    }
    endif;

    Next, you would need to call the above function beneath the title in your child theme’s content-single.php file:

    <header class="entry-header">
    		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
    		<div class="entry-meta">
    			<?php boardwalk_child_entry_meta(); ?>
    		</div><!-- .entry-meta -->
    </header><!-- .entry-header -->

    Let me know how you get on with that! The important thing to start with is to get the category and author information beneath the title. It might not be styled correctly at first, but we can work on that afterwards. 🙂

    Thread Starter F Ran

    (@lobovcf)

    It works! I had to fight a little because information was repeated and it cost me understand why, but it’s settled. I thought, to better manage information, I will create two functions, one for the author and another one for the category. Then I have to give it style. Can you say me how to deal with CSS these new lines that I have created?

    Again thanks for the help;)

    Yay, I’m so glad to hear you were able to get this working. 🙂

    Would you be able to provide a link to your site? This makes it a lot easier for me to be able to guide you with the correct CSS.

    From my own test site, the following CSS go everything lined up correctly when added to my child theme’s style.css file:

    .entry-header .entry-meta a {
        display: inline-block;
        padding-right: 0;
        padding-left: 0;
    }
    
    .entry-header .entry-meta span {
        padding-right: 20px;
    }

    Hope that’s helpful! If you can provide a link to your site then I’ll be happy to guide further, also.

    Thread Starter F Ran

    (@lobovcf)

    My test site is not online, I can not give you a link. In the future, if I get everything to work well, I’ll keep Boardwalk theme working on cafemestalla.com

    Thank you very much. I sincerely appreciate your help.

    But I don’t close the topic. If I have more questions I ask you for help right here 😉

    You’re welcome, Lobo. If you have further questions while setting up your theme then please open up another thread on these forums and we’ll help out from there. 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Category and author under the title’ is closed to new replies.