WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Eleven - Set ALL posts to use one navigation template? (22 posts)

  1. insurgenesis
    Member
    Posted 1 year ago #

    Hi all,
    I appreciate the ability to dynamically reconstruct content but the effect is sometimes confusing...

    In my CHILD THEME I can control category posts order BUT a "single" post is don't display category_archive_meta and page navigation...

    The category template uses page navigation and can cycle through all posts in a category BUT if I click a link to a post in another category it seems to dynamically generate a "single" post that is isolated from the category cycle and page navigation is gone or defunct.

    How can I set ONE template to be used for ALL posts - such as category.php instead of using multiple ones?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    In theory, you can just use a single index.php template file. Within the template hierarchy, that is the default template for everything. See Theme_Development.

  3. insurgenesis
    Member
    Posted 1 year ago #

    Hi Esmi, thanks for prompt response!

    Wouldn't it weigh to heavily if everything is composed with index.php?

    Ideally I'll keep index.php and category.php but I don't understand why single posts (presumably using single.php and content-single.php) produce this "isolated" result.

    So I fantasised that killing the "single" templates would result in posts acquiring the qualities of catagory.php.

    Will that in fact be the case or only fantasy?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Wouldn't it weigh to heavily if everything is composed with index.php?

    Not sure what you mean by "weigh to heavily".

    One of the older default WordPress themes (Classic) had very few theme template files. Themes still exist with only 1 or 2 template files. But these are standalone themes - not child themes. A child inherits its parent's template files automatically. So you can't create a single template child theme and expect the parent's files to be ignored.

    I fantasised that killing the "single" templates would result in posts acquiring the qualities of catagory.php

    Putting aside the fact that you cannot "kill" a parent template via the child, in the situation you describe, a standalone theme without a single.php file would fallback to using index.php.

  5. insurgenesis
    Member
    Posted 1 year ago #

    OK being a child theme of Twenty Eleven, and putting aside the possibility of killing any of its templates, I should still be able to modify the single.php and content-single.php of the child theme to be identical to its the category.php. True?

    You see I need single posts to look like they belong in categories (which they do). Otherwise, if single templates have a different way of cycling through successive posts within their category using default navigation, and jumping to adjacent categories when you reach "the end", as it were, it's very confusing for a user.

    Honestly, do you know what I mean? Forgive me for using metaphorical language - I don't know any better.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    I should still be able to modify the single.php and content-single.php of the child theme to be identical to its the category.php. True?

    Yes - that should be possible if you create new single.php and content-single.php template files.

    I need single posts to look like they belong in categories

    What is it that you are trying to do? Format posts visually to establish a conceptual link to a specific category? Like have all posts from Cat A with a blue background and post for Cat B having a red background?

  7. insurgenesis
    Member
    Posted 1 year ago #

    Like have all posts from Cat A with a blue background and post for Cat B having a red background?

    No, precisely Not like that - it has to have a consistent presentational style.

    I need to include the same navigation method that category.php employs to cycle through posts in a category for single posts, so that single posts never appear outside their category cycles as disparate content pieces - if you know what I mean - to avoid this (established in 1st post):

    The category template uses page navigation and can cycle through all posts in a category BUT if I click a link to a post in another category it seems to dynamically generate a "single" post that is isolated from the category cycle and page navigation is gone or defunct.

    BTW I sincerely hope you know what I mean and that this is a standardised design feature and not a glitch of sorts because if you do not know it's unlikely that others will - considering the semantic difficulty of describing my problem...

    Will it help if I drop the code into paste bin?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    I think I understand what you mean. Assuming I am correct in my understanding, have you had a look at:

    https://codex.wordpress.org/Function_Reference/next_post_link
    https://codex.wordpress.org/Function_Reference/previous_post_link

    Specifically the in_same_cat argument. Does that help?

  9. insurgenesis
    Member
    Posted 1 year ago #

    Thanks for that - there are some nice ones but they don't fit the criteria.
    I need to limit single posts to their own category without the possibility of jumping to adjacent categories - something like "Text As Link, With Post Title, Within Same Category And Limited To That Category". I also don't see this working: "Within Same Category, Excluding One" because I'll want to exclude "All Others".
    Is there an "All" delimiter?

  10. insurgenesis
    Member
    Posted 1 year ago #

    Anyway, for enhanced navigation I used a custom child theme function and invoked it in index.php and category.php by replacing
    <?php twentyeleven_content_nav( 'nav-below' ); ?> with
    <?php function_pagination(); ?> producing good results.

    Problem is that <?php twentyeleven_content_nav( 'nav-below' ); ?> does not appear in either single.php or content-single.php because it uses <nav id="nav-single"> instead.
    I can't simply replace this as with the others (so it's not going to be a pasting exercise) and I will have to invoke the navigation function in a way I'm not familiar with.

    Q: What is the correct way to invoke that function from within single.php and content-single then?

  11. esmi
    Forum Moderator
    Posted 1 year ago #

    I'm not sure why you can't just call <?php function_pagination(); ?> in place of:

    <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>

    Is this a styling issue? Or perhaps you need to create function_pagination_single() as an amended version of the custom function? Invoking a custom function is pretty straightforward. If it's in your theme's functions.php file, you can call it in any template file. The specifics might vary (for example, do you need to declare global $post; in the new function or pass it some other variable) but that's about it.

  12. insurgenesis
    Member
    Posted 1 year ago #

    Thanks again for checking back. Truthfully I don't know what

    declare global $spot

    means or how to

    amend a version of the custom function

    though my intuition is to amend.

    All I know is it doesn't work to simply replace the <spans>
    and calling (previously invoking) with function_pagination_single() from within the singles.

    If I can successfully call that function from within the template files which compose single posts, I will have consistent cross-site navigation.

  13. esmi
    Forum Moderator
    Posted 1 year ago #

    declare global $spot

    Sorry! Typo! That should have been global $post; (I swear my fingers are dyslexic). Sometimes required when you need access to a posts object within a function.

    What exactly is in function_pagination()? Why won't it work in single.php? What happens?

  14. insurgenesis
    Member
    Posted 1 year ago #

    Nothing happens.

    Here it is: http://pastebin.com/G1TNrTnv

  15. esmi
    Forum Moderator
    Posted 1 year ago #

    You're not taking single Posts into account using (for example) the is_single() conditional. I think you need to code for them separately - possibly around if(1 != $pages) as $pages is always going to equal 1 on a single Post.

  16. insurgenesis
    Member
    Posted 1 year ago #

    I'm not sure how to do that. If you happen to know but feel you don't want to disclose, just do it anyway and send me your Amazon wishlist ;)

    Do you mean "code separately" like two discrete functions - one for category and one for singles?

    But why does it not show up when I call it in single?

  17. esmi
    Forum Moderator
    Posted 1 year ago #

    ok - I've done done testing locally. On any singular page (ie Pages and single Posts), $wp_query->max_num_pages is zero, so $pages is set to 1 by if(!$pages ) $pages = 1;.

    But then you're only outputting any pagination/navigation content if( $pages != 1 ). So single Posts always fail that if clause. What I think you need to do is to take the last part of the code outside of that if block. See http://pastebin.com/1Ynctg81

  18. insurgenesis
    Member
    Posted 1 year ago #

    Thank you for looking at it. I tried without success but wil scrutinise the code again.

    I just wish there was a way avoid the singles OR to get them to function and look like category.php.
    Evidently it requires a bit more than collaging what I think I need in there. The fact that single is modularised like that makes it very compelling but more challenging to supplant.

    I'm struggling to come to terms with the purpose of the singles and how to make them work for me. In my case it would Never be useful to present a single piece of content that is stripped from its context and its sequence in a category cycle.

  19. Racep 8561
    Member
    Posted 1 year ago #

    oye,como creo un blog?

  20. insurgenesis
    Member
    Posted 1 year ago #

    @Racep 8561,
    You do realise that even by divine grace & google translate your input has no bearing on the issue at hand. Were you going to proffer sensible commentary as well?
    Esmi and hope to enhance our readers' experience but can only do so when you provide comprehensible feedback.
    Really, do you think I would work my way up to 20 posts for the entertainment of others?

  21. insurgenesis
    Member
    Posted 1 year ago #

    @esmi, I still cannot figure out why it's impossible to call the the function. It works when called from category.php but not from the singles. I have no idea what to try next.

  22. esmi
    Forum Moderator
    Posted 1 year ago #

    Sorry - been ill. :-( The code I posted in the pastebin works for me in single.php when used in a Twenty Eleven child theme.

Topic Closed

This topic has been closed to new replies.

About this Topic