php - Simple query for Wordpress posts & excerpts -
I am trying to create a small "latest news" section on my custom homepage in Wordpress, which outputs
& lt ;; Php // the query $ The_query = New WP_Query ('post_count = 2'); // Loop if ($ the_query-> is_pause ()) {echo ' is_post ()) {$ the_query-> The_post (); Echo & lt; Li & gt; '. Get_the_title () '& lt; / Li & gt; '; } Echo '& lt; / Ul & gt; '; } Else {// There is no post 'echo' There is no news good news! '; } / * Restore original post data * / wp_reset_postdata (); ? & Gt;
This code currently has two published posts that show "No news is not good news" message.
Your code presents output in my favor, so it is working. You have a problem, however, postcount
is a property and its parameter is not you should use posts_per_page
I believe that why Why is it that you have not got any output, it is that you are using a custom post type, and not a normal post, which will not present any output as this case because you do not have any general posts.
Just change this line
$ the_query = new WP_Query ('post_count = 2');
to
$ the_query = new WP_Query ('posts_per_page = 2 & amp; post_type = NAME_OF_POST_TYPE');
Comments
Post a Comment