• llwvc

    (@llwvc)


    I need to create a child theme for the default Twenty Fourteen theme. And in this child theme, I need to modify the single.php.

    This is the default single.php:

    get_header(); ?>
    
        <div id="primary" class="content-area">
            <div id="content" class="site-content" role="main">
                <?php
                    // Start the Loop.
                    while ( have_posts() ) : the_post();
    
                        /*
                         * Include the post format-specific template for the content. If you want to
                         * use this in a child theme, then include a file called called content-___.php
                         * (where ___ is the post format) and that will be used instead.
                         */
                        get_template_part( 'content', get_post_format() );
    
                        // Previous/next post navigation.
                        twentyfourteen_post_nav();
    
                        // If comments are open or we have at least one comment, load up the comment template.
                        if ( comments_open() || get_comments_number() ) {
                            comments_template();
                        }
                    endwhile;
                ?>
            </div><!-- #content -->
        </div><!-- #primary -->
    
    <?php
    get_sidebar( 'content' );
    get_sidebar();
    get_footer();

    I now need to do two things:

    First, Add some sharing buttons in my post. The codes for these buttons are

    <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div>
    
    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdPic":"","bdStyle":"0","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='https://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>

    Second, Add some variable from Advanced Custom Fields in the post. The codes are like:

    <p><?php the_field('field_name'); ?></p>

    I don’t know where to add these codes. I tried to insert theme between some lines, but that causes the theme to stop working.

    Please help! I need to where to add these lines of codes.

    Thank you so much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter llwvc

    (@llwvc)

    I tried to modify the single.php file. I don’t want to edit the content file since it also changes the appearance of the front page and archive page and the search result page. I only want to add some things to the Full Post page.

    nadyaQL

    (@nadyaql)

    any luck? im trying to do the same!

    The only way I’ve found to modify the single post page is to change a the file template-tags.php
    It creates the navigation of the previous and the latest posts. So, if you insert the code of your social icons block above the navigation, you’ll have them just after your post.
    You are to insert your code after this line:

    // Don't print empty markup if there's nowhere to navigate.
    	$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    	$next     = get_adjacent_post( false, '', false );
    
    	if ( ! $next && ! $previous ) {
    		return;
    	}
    
    	?>

    And before that

    <nav class="navigation post-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
    		<div class="nav-links">

    Changes in the file content.php doesn’t make sence, cause the file also participates in the creating of the other pages, like the main one.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Modify Twenty Fourteen Child Theme Single.php’ is closed to new replies.