Domanda

I'll start saying I'm terrible at PHP. I can modify some simple codes but I have no clue about what I'm doing when I have to write my own.

The Goal: Display 2 loops on my wordpress index.php page from 1 specific category. The first loop should display a sticky post, the second all the other posts.

The Category I would like to display is '28'.

I have found this page: http://codex.wordpress.org/Sticky_Posts but I don't know how to put it in action.

I have spend hours to try and get it to work but without any success.

So loop 1 should be like this:

--- cat is 28 show post id35.

Loop 2 should be like this:

--- cat is 28 show all non sticky posts (so exclude stickies)

If someone could help me I'd be so happy. It's been 2 days and still I can't get it together >.>

Thanks!

È stato utile?

Soluzione

Get the Latest Sticky Post.

<?php
$sticky = get_option( ‘sticky_posts’ );
query_posts( array( ‘cat’ => 28, ‘post__in’ => $sticky, ‘orderby’ => ID, ‘showposts’ => 2 ) );
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>

Exclude sticky posts from a list of recent posts

<?php $sticky = get_option(‘sticky_posts’) ;

$post_to_exclude[] = $sticky[0];

$args=array(
‘cat’ => 28,
‘showposts’=>10,
‘post__not_in’=> $post_to_exclude,
);

query_posts($args); ?>

<h2><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a> </h2>

<?php while (have_posts()) : the_post();  ?>

<?php endwhile;?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top