Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to have a sticky post for all my pages and categories. The choice of "sticky post" in the edit post, didn't work. I found many pieces of code but I haven't the result that I want. I prefer to implement coded and not with a plugin.

Any help? Thanks in advanced.

share|improve this question
    
Hi and sorry for the -1 welcome, but what do you mean by "all my pages and categories"? What "didn't work"? What have you tried with the pieces of code you found? This place is mainly about code, and plugin recommendations are off-topic. Please, take a look here: wordpress.stackexchange.com/questions/how-to-ask –  brasofilo Dec 3 '12 at 23:20
    
I accept your opinion,i don't have any problem with -1.One of solution.I select my sticky posts $stickies = new WP_Query(); the loop statement is like this: while($stickies->have_posts()):$stickies->the_post() The newsposts are selected this way query_posts('category_name=Uncategorized&paged=' . $paged .''); // the loop while(have_posts()): the_post();$stickies->query(array('post__in'=>get_option('sticky_posts'))); –  MikeD Dec 4 '12 at 0:27
1  
Please, Mike, add new information to the Question itself. You can update it whenever needed. And code snippets belong to the Q. The better the Q, the better Answers you'll receive. –  brasofilo Dec 4 '12 at 0:39
    
Αccurate observation, but i work with another part of code. ok i will be back during the daytime. Thanks again –  MikeD Dec 4 '12 at 2:46
add comment

1 Answer

up vote -1 down vote accepted
$sticky = get_option( 'sticky_posts' );
$args = array(
    'posts_per_page' => 1,
    'post__in'  => $sticky,
    'ignore_sticky_posts' => 1
);
query_posts( $args );
if ( $sticky[0] ) {
    // insert here your stuff...
}
share|improve this answer
    
Please explain your answer. And don’t use query_posts(). –  toscho Dec 4 '12 at 12:08
    
Can you explain why i can't use query_posts()...? –  user205215 Dec 4 '12 at 12:20
    
    
oh i am back again. I am sorry for the delay.Finally, I want to do a post sticky only to homepage. I try to write code for this part, and i will be back in few hours. –  MikeD Dec 7 '12 at 20:33
    
I activate a post to sticky but the problem is that the sticky post can not customize with css. In the style.css i have the css style of sticky post.. Where is the problem? Also can we edit the title of post? The correct title : How to enable and customize a sticky post to homepage?" Thanks in advance. –  MikeD Dec 8 '12 at 15:29
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.