• Resolved HopefulGJL

    (@hopefulgjl)


    Hello,

    I have php code that is working to customize the sidebars of my pages. I’m wondering how, or if, this code could be altered to instead target post and category id’s?

    <?php if (is_page('100')) : ?>
      	<?php get_sidebar('homepage'); ?>
      <?php else : ?>
       	<?php get_sidebar(); ?>
      <?php endif; ?>

    I know very little about code, so please be as specific as possible. Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Digest WP

    (@jay-stankiewicz)

    Hello,

    It can be done but it is not as simple as pages.

    This should help you

    https://lestini.com/blog/463/pulling-posts-into-the-sidebar-in-wordpress/

    Thread Starter HopefulGJL

    (@hopefulgjl)

    That does look interesting, thanks for that information.

    That said, it looks like she’s trying to pull post information in to her sidebar.

    I am looking to input something unique that I put in to the sidebar of the posts instead.

    So, if it’s post 1, then I want to display A on the sidebar.
    If it’s post 2, then I want to display B on the sidebar
    If it’s category 3, then I want to display C on the sidebar, etc.

    (By unique, I mean A, B and C is code that I have from outside of my site itself; like code to link to other sites or merchandise to buy that is customized to that specific page, etc.)

    I’m not sure that the description of what her code is doing will work for what I’m looking to do?

    I really hope to find the code, otherwise I guess I’m going to take all of my posts, make them in to pages instead, and never use posts or categories since I know my method works to customize pages. It just means redoing a whole ton of links.

    I hope I don’t have to do that?
    (Please note I’m looking to avoid using plug-ins – I have my reasons.)

    Thanks!

    Thread Starter HopefulGJL

    (@hopefulgjl)

    I’ve got it!

    <?php if (is_single('100')) : ?>
      	<?php get_sidebar('homepage'); ?>
      <?php else : ?>
       	<?php get_sidebar(); ?>
      <?php endif; ?>

    Just change the is_page with the is_single and then put the is_page in to your page php file while putting the is_single in to your single (single post) php file where the code otherwise calls for the sidebar(s).

    If you want more information on how to accomplish this, please read my last post here.

    I also found more information here.

    And, it looks like that codex article I linked to explains how to do the categories.

    Thank-you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can this page code for sidebars be altered for posts and category id's?’ is closed to new replies.