SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    differentiating posts

    Hello all, working w/a child theme of 2014, although am sure this would apply to any theme
    I would like a set of posts in the primary bar an diff set in the secondary.
    I thought i could just tag & add a category to the post then specify that in the function calling it.
    but it didn't work(or i could have done it incorrectly?).
    Has anyone here dealt w/this and can you please share how you fixed it?


    Thank you
    D

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Can you show us how you did it?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey Guido...not much to show as I have not managed to do it. still looking at the files to see what to target.
    as is functions.php of course has the widget_init area but i wouldn't touch that to select the posts.
    in sidebar-content.php there is
    Code:
    <?php dynamic_sidbar('sidebar-2'); ?>
    so i think that is where i might add the code?
    but can't find the specific code yet were I might be able to just add category & title so only that displays in sidebar 2

  4. #4
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok so this was the latest thing i tried

    PHP Code:
    <ul>
    <?php query_posts('cat=seasonal&showposts=5'); ?>
    <?php 
    while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    I only have two posts so far I have given to a category of "seasonal" but six posts in total. according to the code above only the two seasonals ones should show up. instead all posts still show.

    I can get the post i want to show up by selecting them one by one & calling them by cat & tag. but that is not automated and would need for the coder to update the code whenever there is a new "seasonal" post.

    So what am I doing wrong?
    thank you
    D

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I've read a bit in the WP codex, and it seems query_posts is not recommended.
    If you want to change the main loop, take a look at http://codex.wordpress.org/Plugin_AP.../pre_get_posts
    If you want to add another loop, take a look at http://codex.wordpress.org/Template_Tags/get_posts

  6. #6
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    get_post didn't work. & i did add wp_reset_query()
    also that wouldn't address the issue. I want only posts in certain categories to show. Not all the posts.
    D

  7. #7
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok sharing this in case this works for someone else. thanks to chris in the wordpress.org forum for pointing me in the right direction. The one thing i haven't gotten yet is the limiting of the posts. His way didn't work but happy w/this progress so far.

    PHP Code:
    <?php
    $new_query 
    = new WP_Query(
            
    'category_name=seasonal' 
        
    );
    while ( 
    $new_query->have_posts() ) : $new_query->the_post();
    ?>

    <li>
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
        <?php the_excerpt(); ?>    
        <hr>
    </li>
    <?php
    endwhile;
    ?>

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Did you try
    PHP Code:
     <?php
    $args 
    = array(
            
    'category_name'     => 'seasonal',
            
    'posts_per_page'    => '5'
        
    );
    $new_query = new WP_Query($args);

    while ( 
    $new_query->have_posts() ) : $new_query->the_post();
    ?>

    <li>
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
        <?php the_excerpt(); ?>    
        <hr>
    </li>
    <?php
    endwhile;
    ?>

  9. #9
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    that didn't work for me the first time i tried, but will give it another shot to make sure there were no typos on my part.
    thank you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •