• Hi,

    I am trying to add a javascript widget at the bottom of every one of my blog posts, basically its a widget for related posts on other websites.

    I cant find which part of my theme to edit in order make this appear only at the bottom of the post pages.

    A couple of attempts I tried had the widget appear in the correct position, but it also appeared under every post on the homepage (which I do not want it to appear on at all).

    Any guidance in this would be much appreciated.

    Thanks,

Viewing 9 replies - 1 through 9 (of 9 total)
  • Do you want this to appear at the bottom of every post or at the bottom of all your post pages? You say both things in your post.

    I’m going to assume you want it once, at the bottom of your post pages. The principals are the same regardless of which interpretation of your question is the right one.

    Take a look at the WordPress Template Hierarchy.

    You need to identify what templates your theme uses and how it outputs the list pages you are interested in, like blog postings, category lists, archive lists and so on. Then you need to follow the hierarchy, checking what files exist in your installation that are likely to need to be changed. For example, the default twenty eleven theme has the files index.php, archive.php, category.php and many more. Any one of these might be used, depending on the kind of list being output, so you would need to create a child theme and alter every one of them that was of interest to you.

    On the other hand, the twenty ten theme that is also one of the defaults, does things differently. It uses a single loop.php file that deals with the various types of listing, whilst it has specialised versions of the loop in files like loop-attachment.php and loop-page.php for other types of output. So if you were using twenty ten you would create a child theme and alter the relevant loop*.php files.

    Incidentally, if you are using a non-standard theme, you should carefully consider using a child theme for your changes. If you are using a default theme like twenty eleven or twenty ten you should always use a child theme. Always.

    HTH

    PAE

    Thread Starter ngod23

    (@ngod23)

    Hi Peredur,

    Thanks for your feedback, yes ideally I would like the widget to appear at the bottom of the post pages, just below the comments section.

    The theme I am using is a custom theme created with the programme artiseer.

    The best place would likely be in footer.php, I tend to add the code in a template part and call this in the footer.php file.

    This is not an Artisteer theme footer ribbon tutorial, but the workflow would be the same.

    1. create a file footer-latest.php add your latest posts code in this file.

    2. In footer.php call the template part.

    <?php
    //Add the footer latest posts
    if( is_single() ) {
       get_template_part( 'footer', 'latest' );
    }
    ?>

    Edited after comment(Peredur): for single page only
    HTH

    David

    Ah! OK. Single post pages…

    Right, if you go back and look at the WordPress Template Hierarchy, you’ll see that the possible pages you’ve got to deal with are those where either is_single() or is_attachment() is true. You’re probably not bothered about the is_attachment() line, I assume, so you need to look for these files:

    • single-*.php
    • single.php
    • index.php

    Any, or all, of those files might be outputting the HTML that goes into a single post. Unfortunately, you’re going to have to do some detective work, because there are a number of different strategies that a theme can adopt. For instance, the default twenty eleven theme has a single.php file with code like this in it:

    <?php
    get_header(); ?>
      <div id="primary">
        <div id="content" role="main">
          <?php while ( have_posts() ) : the_post(); ?>
            <nav id="nav-single">
              <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    	  <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?></span>
    	  <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></span>
    	</nav><!-- #nav-single -->
          <?php get_template_part( 'content', 'single' ); ?>
        <?php comments_template( '', true ); ?>
        <?php endwhile; // end of the loop. ?>
      </div><!-- #content -->
    </div><!-- #primary -->
    <?php get_footer(); ?>

    Notice that this calls (or includes) another file called either content.php or content-single.php. As it happens, content-single.php exists so it is the code in there that runs.

    Depending on exactly what you want, you may want to inject your code into one or other of these files. It will depend on exactly where you want your code to appear.

    Turning to the twenty ten default theme, we see a different strategy. In twenty ten there is a single.php file that looks like this:

    <?php
      get_header(); ?>
      <div id="container">
        <div id="content" role="main">
          <?php
    	get_template_part( 'loop', 'single' );
          ?>
        </div><!-- #content -->
      </div><!-- #container -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    As you can see, this calls a file called either loop-single.php or loop.php. By default, twenty ten has a loop-single.php file and it is this one that will be called (included).

    Again, you examine the code to see where you want to inject your own code, and into what file.

    If you need help in determining where the code should go it would greatly assist us if you posted a link to a sample page with a description of exactly where you want the new output to be.

    Just a thought. If you have a custom theme, shouldn’t the person who created that theme be doing these changes?

    Cheers

    PAE

    Hi Peredur,
    The OP has a the third party paid for Artisteer theme generation software, this generates custom themes and assets out the box, for WordPress and other CMS’s, but in a slightly different structure.

    Regards

    David

    @digital Raindrops

    Re footer:

    Yes. Thought of that. It would have to be added conditionally, though. It only wants to appear on single post pages, if I understand it correctly.

    Cheers

    PAE

    @digital Raindrops

    Re footer:

    Yes. Thought of that. It would have to be added conditionally, though. It only wants to appear on single post pages, if I understand it correctly.

    Cheers

    PAE

    Thanks,
    I have updated this topic post,

    The code in the tutorial link has the is_single() condition, just in case I have updated the snippet above to mirror this.

    Regards

    David

    Yes. I’m sure that’s the best solution.

    Cheers

    PAE

    Thread Starter ngod23

    (@ngod23)

    Brilliant thanks guys ill give it a try.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Help editing template for post pages only’ is closed to new replies.