WordPress.org

Forums

WordPress Post Query (9 posts)

  1. b4db0y
    Member
    Posted 2 years ago #

    I wanted to know if there was a query or one could create a query like

    if is category and if sticky display the post else do nothing?

    Thanks

  2. raskull
    Member
    Posted 2 years ago #

    Maybe there's something here for you: http://codex.wordpress.org/Function_Reference/query_posts?

  3. b4db0y
    Member
    Posted 2 years ago #

    I tried that, but am not able to get it to work.

  4. raskull
    Member
    Posted 2 years ago #

    <?php
    //return sticky posts in categories 3 and 7
    query_posts(array(
    	'post__in'=>get_option('sticky_posts'),
    	'cat'=>'3,7'
    	));
    if (have_posts()) : while (have_posts()) : the_post();
    ?>
  5. b4db0y
    Member
    Posted 2 years ago #

    thanks raskull.
    I edited some parts

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $sticky=get_option('sticky_posts');
    $args=array(
    'cat'=>232,
    'caller_get_posts'=>1,
    'post__in' => $sticky,
    'paged'=>$paged,
    );
    query_posts($args); while ( have_posts() ) : the_post()  ?>

    Wanted to know, isn't there any way for the cat number to autofill, like if the user in on the autos category it is filled as autos

  6. raskull
    Member
    Posted 2 years ago #

    Tell me more about how/where you plan to use this...

  7. b4db0y
    Member
    Posted 2 years ago #

    i will be having a classified theme (study related)

    where there be categories like
    - ACCA
    - O Levels
    - A Levels
    - Matriculate
    - Intermediate
    etc.

    If the user visits acca, the sticky posts of ACCA be shown.
    If he visits o levls, the sticky from that category is posted.
    and so on.

    Again thankyou

  8. raskull
    Member
    Posted 2 years ago #

    Do you have a file named category.php? That might go a long way towards what you're looking for. It's what results if you click a category link (if you have category.php, otherwise it moves on to archive.php). Take a look in archive.php to see what's going on -- you only need the part related to category to put in your category.php file.

    http://codex.wordpress.org/Template_Hierarchy
    http://codex.wordpress.org/Category_Templates

    My point is -- category.php already knows what category to display because it came from a category link. Let me know if that doesn't help!

  9. b4db0y
    Member
    Posted 2 years ago #

    got it working ...thankz

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags