• Resolved DarkMage530

    (@darkmage530)


    I’m a little confused. I’ve filled in some junk content just to test out my child template. I’ve got a “Static Home Page” and I’ve made the home page a “Recent Posts”. I’ve also created a handful of posts that use a category.

    When I click on the title of one of these posts from the “Recent Posts” it ends up displaying all the posts. Playing around with the Category and Single templates it seems the category template is being used to generate the content instead of the single template. This is confusing because looking at the TemplateHierarchy help page it says that single.php should be invoked for “Single Post Display”. I would assume clicking on the title of a Post would be considered trying to display a Single Post.

    But instead it pulls up the Category Archive.

    Well I’ve looked at this diagram a bit

    And it appears that to get the single.php invoked it needs to first pass the “is_singular()” boolean. And that leads to a “Single Post Page” which seems to imply it’s a Page and not a Post. So I looked up “Single Post Page” and read through this which didn’t really answer my question.

    As the top answer says the Single Post Page means “The web page that only displays one, single, Post” which brings me back to, why is it that when I click on the title of a Post in order to view the Single instance of that post, it invokes the category instead of the single. And if it keeps invoking the category how do I get it to display ONLY that one post that I clicked on and not the most recent 5 or whatever.

    I keep going in circles and am really frustrated by something that I feel should be absurdly simple.

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Can you please post the custom query loop code from your custom page template you’re using for your static front page?

    Thread Starter DarkMage530

    (@darkmage530)

    Well I’m not actually using the Loop on my static front page. Since I’m still just playing around and trying to figure out themes. I’m also not sure why the static front page would effect it. The file is named static-home.php since the How to: for Static Front Page explicitly stated not to call it home.php. Which is what I named the “Recent Posts” page.

    static-home.php:

    <?php /* Template Name: static-home */ ?>
    <?php /**
     * This is my form of a static home for now
     * It will be updated in the future
     * @package WordPress
     * @subpackage Twenty_Eleven
     */ get_header(); ?>
    		<div id="primary">
    			<div id="content" role="main">
    				<header class="entry-header">
    					<h1 class="entry-title"><?php _e( 'Static Home Page', 'twentyeleven' ); ?></h1>
    				</header><!-- .entry-header -->
    				<div class="entry-content">
    					<p><?php _e( 'Testing testing static home testing', 'twentyeleven' ); ?></p>
    				</div><!-- .entry-content -->
    			</div><!-- #content -->
    		</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    home.php:

    <?php
    /**
     * @package WordPress
     * @subpackage Twenty_Eleven
     */ get_header(); ?>
    	<div id="primary">
    		<div id="content" role="main">
    			<?php if ( have_posts() ) : ?>
    				<?php twentyeleven_content_nav( 'nav-above' ); ?>
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    					<?php get_template_part( 'content', get_post_format() ); ?>
    				<?php endwhile; ?>
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    			<?php endif; ?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    As you can see I’m using the twentyeleven theme as a base and I created a child theme that imports from twentyeleven.

    Okay, sorry; you had me a bit confused with:

    I’ve got a “Static Home Page” and I’ve made the home page a “Recent Posts”. I’ve also created a handful of posts that use a category.

    Note: you don’t actually need a home.php. WordPress will safely fall back to use index.php for your blog posts index. So, you can try renaming that template file, and see if issues are resolved.

    Other questions:

    1) What page is assigned to the Front Page
    2) What page is assigned to the Posts Page

    (You can find these settings via Dashboard -> Settings -> Reading.)

    Thread Starter DarkMage530

    (@darkmage530)

    I had the ‘Front Page’ set to HomeStatic and ‘Posts Page’ set to RecentPosts.

    I tried renaming the home.php to something different so that it picks up the index.php by default. That didn’t seem to change anything. It still displays the most recent posts as it iterates through the loop. The only difference was that it didn’t have my custom display lines that I’ve been using to identify which templates are being used and where.

    as an example:
    <h1>the loop Category.php</h1>
    I’ve added lines like this to my static-home.php, home.php, category.php, and single.php. When I click the title of a Post I should see just that one post. I would anticipate I’d see the single.php identifier line but I see only the category one.

    I’m a little confused as to why the home page and static-home page would effect the use between single and category.

    Thanks for the continued help

    I’m a little confused as to why the home page and static-home page would effect the use between single and category.

    It shouldn’t. I’m just laying some investigative groundwork, to make sure you’ve got everything configured normally, and don’t have any custom template/loop issues. ??

    Next question: do you have a live link where we can see the issue “live”?

    Thread Starter DarkMage530

    (@darkmage530)

    Ah I see, that makes sense.

    Sure, https://darkmage530.freeiz.com/

    Right now I only have 5 files in my child theme for overriding the twentyeleven theme. That is styles.css, static-home.php, home.php, category.php, and single.php

    Clicking that link will load up the static-home.php. Clicking “Recent” on the header will take you to home.php which will show my 3 sample posts. Clicking the third header currently named “My Anime” will take you to a Page where I have added links among other text to my 3 sample posts.

    Clicking on the title of one of the posts from “Recent” or one of the links in the “My Anime” Page pulls up the category.php with the 3 sample posts listed in the same order regardless of what the URL is in the browser.

    I’ll add the category.php and the single.php code below. I removed some superfluous code on some pages like the sidebar, the else statements from the if (has_posts) and other parts of code that was just noise for now.

    Here is the code for category.php

    <?php /**  * The template for displaying Category Archive pages.
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0 */
    get_header(); ?>
    		<h1>after header CATEGORY.php</h1>
    	<section id="primary">
    		<div id="content" role="main">
    
    		<?php if ( have_posts() ) : ?>
    				<?php twentyeleven_content_nav( 'nav-above' ); ?>
    
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    			<h1>the loop CATEGORY.php</h1>
    					<?php
    						/* Include the Post-Format-specific template for the content.
    						 * If you want to overload this in a child theme then include a file
    						 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    						 */
    						get_template_part( 'content', get_post_format() );
    					?>
    
    				<?php endwhile; ?>
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    			<?php endif; ?>
    
    			</div><!-- #content -->
    		</section><!-- #primary -->
    <h1>before sidebar CATEGORY.php</h1>
    <?php get_footer(); ?>

    and for single.php

    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); ?>
    		<h1>after header SINGLE.php</h1>
    		<div id="primary">
    			<div id="content" role="main">
    
    				<?php while ( have_posts() ) : the_post(); ?>
    		<h1>the loop SINGLE.php</h1>
    					<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">←</span> Previous', 'twentyeleven' ) ); ?></span>
    						<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></span>
    					</nav><!-- #nav-single -->
    
    					<?php get_template_part( 'content-single', get_post_format() ); ?>
    
    					<?php comments_template( '', true ); ?>
    
    				<?php endwhile; // end of the loop. ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    		<h1>before footer SINGLE.php</h1>
    <?php get_footer(); ?>

    Like I said most of this is just sample garbage stuff just to learn how to manipulate the themes and templates and figure out what is going on. Thanks again, let me know if you need any more information.

    Do you have a functions.php in your Child Theme?
    Do you have any Plugins active?
    What is your permalink setting? What happens if you reset your permalink settings?

    And if all else fails: what happens if you switch to Twenty Twelve directly?

    Thread Starter DarkMage530

    (@darkmage530)

    There is no functions.php in my child theme. But there is one inside the imported twentyeleven theme. Which is unchanged from the original.

    There are 2 plugins listed but both are inactive.

    My permalinks settings are currently
    Common Settings: Custom Structure: /%category%/%year%/%post_id%
    Category Base: category
    Tag Base: tag

    If I activate twentytwelve without doing anything else, it appears to act in a similar manner as my child theme. Clicking on a link or a title to go to a particular post displays my 3 posts in the same order as before. The only other noticeable changes are colors, the sidebar I had removed, and my custom <h1>filename.php</h1>identifier comments.

    Thread Starter DarkMage530

    (@darkmage530)

    All I really want is when I click this link
    https://darkmage530.freeiz.com/anime/2013/17

    It only shows the post with post_id 17

    And when I click this link
    https://darkmage530.freeiz.com/anime/2013/15

    I am only shown the post with post_id 15.

    Instead both links lead to exactly the same thing. I assumed the issue was because it’s using the category.php template instead of the single.php template. That may be an incorrect assumption.

    This should not be something difficult to do and why it’s not default behavior is mind-boggling. Since 99% of the blogs I’ve been to behave the way I described.

    Here’s the issue:

    Common Settings: Custom Structure: /%category%/%year%/%post_id%

    But I *think* WordPress is interpreting %post_id% as month. WordPress can be flaky with numbers on the end of permalink structures (such a an all-numeric post name (title), and perhaps in this case as well).

    First, try changing permalinks back to default (no rewrites), and see if your permalinks work properly again.

    Then, try changing the last part of your custom permalink structure to post name instead of post ID, and see if it works.

    Thread Starter DarkMage530

    (@darkmage530)

    Hmmmmm very interesting. I changed the permalinks to the default and it worked as I expected. I then changed %post_id% to %postname% and again it worked as expected. I tried a couple different variations including %category%/%post_id% and everything worked as I expected except when I had %post_id% as last.

    It certainly sounds like a bug of some kind. Should I file a bugreport for this? Overall it’s a real shame the %post_id% doesn’t work as expected because I liked having short and unique urls.

    It does seem to work as /%post_id%/%category% but doing anything like this defeats the idea of a hierarchical url and also goes against the warning on the Using Permalinks #Structure Tags article. (Although the posts will still unique urls because the %post_id% is being used, just not ending with it)

    And also with a changed permalink structure it is indeed grabbing from the Single.php as I initially expected.

    Thank you very much for the help and the quick replies over the past 24 hours. I appreciate it. If at any point I sounded a little snappy or frustrated, I apologize for that.

    Glad you got it working!

    As for the permalink issue with numeric endpoints: it’s actually a very old problem:
    https://core.trac.www.ads-software.com/ticket/5305

    (Note the ticket number; that’s from 6 years ago. ?? )

    I didn’t search for a ticket for your specific issue, but I would imagine the two issues are related. Feel free to file a trac report; just be sure to reference the one above. Whomever triages it can determine whether they are the same issue, related, or entirely separate issues.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘category.php template being used instead of single.php’ is closed to new replies.