Display posts out of wordpress - wordpress

I need to get some posts by category and display them out of the wordpress. I need these posts hidden in the wp blog. But visible in my custom page. Via php.
I'm noob with wordpress. Can anyone direct me about how can I do that?

Your file should be something like this:
<?php
require '/path/to/wordpress/root/wp-load.php';
$the_query = new WP_Query( 'post_status=private' );
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
?>
Read more about WP_Query class to get posts which you need.

Related

category.php displaying only 10 posts

I want display 30 posts on category.php , but after 10 post loop is terminating where as i have more then 30 posts for particular category . I have tried on category.php with if(have_posts() )
Ohh i got answer .. It is simply SETTINGS -> READING -> Blog pages show at most
#Dibya
try this way to show the number of posts on category.php without affecting blog page
<?php
$query = new WP_Query('category_name=Category&posts_per_page=30');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
if (has_post_thumbnail()) {
?>
<?php the_post_thumbnail(); ?>
<?php
}
?>
<h2><?php the_title(); ?></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>
This can also be resolved using posts_per_page = -1 parameter in wp_query. By using this , you don't need to bother about the backend settings. This will always works.

Wordpress how to create custom post template

Wordpress how to create custom post template from parts of INDEX.php! On my Frontpage (Index.php) i have a great Post Grid. I would like to have this Grid also under each post (Under the Post Content between Comment field). I have copy some parts from the (Index.php) Code and inserted in the post.php but, the result was not satisfactorily.
I have searched everywhere but can not find a satisfying solution, which is compatible with my wordpress theme. If someone can help me, please let me know what code do you need. I would be more than happy to hear a solution!
Thanks in Advance
Not very clear what you mean, but I think you want to print some posts on your single.php file. To accomplished this, you'll need a WP_Query similar to:
<?php
// the query
$args = array(
'post_type' => 'post' // change as needed
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2> <!-- Copy same structure and data as the one on the index.php file -->
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
You will need to keep the same div structure and classes as the one on the index.php to make them look alike.
Good luck!

How to show recently added posts to my custom post category?

I and working on a wordpress website and want to show Title with its permalink of recently added posts in the my custom post category, i have tried many testimonials from the web but failed.
Any one here, suggest me php code to show the custom post type category-recently added.
Thanks
Try this:
<?php
$post_type = 'your custom post type';
$posts_per_page = '5';
$queryObject = new WP_Query( 'post_type='. $post_type .'&posts_per_page='. $posts_per_page );
// The Loop!
if ($queryObject->have_posts()) {
?>
<ul>
<?php
while ($queryObject->have_posts()) {
$queryObject->the_post();
?>
<li><?php the_title(); ?> </li><?php
}
?>
</ul>
<?php
}
?>
Hope this helps you

Listing Post Ids within loop on page?

Is there anyway to list the post IDs for all the posts in the loop on a page in Wordpress?
Id like to make a navigation bar out of the current posts on the page.
Wordpress 3.3
Thanks!!
Use query_posts() to get all posts and loop through it for ids, example:
<?php
// The Query
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>

Retrieve certain posts by their number?

How can I call certain posts by their number to place them as featured posts in specific places of my template ?
I've read about sticky posts , But I have about 3 places to place my featured posts and I guess I need a loop to get posts by their number I defined.
Any HELP ?!
<?php
// The Query
$query = new WP_Query( 'p=7' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>

Resources