Posts from one category outside of WordPress?
-
This question or similar ones has been asked a number of times, but I still haven’t found something that works- there are a number of posts that point in different directions, but I can’t put the pieces all together just right-
The code I am currently using to pull the post title and post content onto my front page that resides outside of WordPress is the code from that Creating a State Front Page with Mini-Loop.
The blog is at https://www.nrcpara.org/paranews/
and the front page where I want to display the lasts 5 posts from one category is:
https://www.nrcpara.org/
ID
<?php<br />
$how_many=5; //How many posts do you want to show<br />
require_once("/var/www/html/paranews/wp-config.php"); // Change this for your path to wp-config.php file ?><br />
<?<br />
$news=$wpdb->get_results("SELECT,
post_title,
post_contentFROM $wpdb->posts<br />
post_status
WHERE= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);<br />
foreach($news as $np){<br />
print ("<h2><a href=\"");<br />
echo get_permalink($np->ID);<br />
print ("\">$np->post_title</h2>");<br />
print ("$np->post_content");<br />
} ?>
I am currently pulling the last 5 posts without any problem, but I can’t narrow it down to one category…I have found a number of ways to do just that inside of WordPress, but no concrete examples on how to do it outside.
The post below suggests to use Template Tags/Query Post instead to get my desired effect, but I have had a difficult time trying to use the query post command outside of WordPress?
https://www.ads-software.com/support/topic/66033?replies=4If anyone could help me out with what to do or point me in the right direction it would be tremendously appreciated-
- The topic ‘Posts from one category outside of WordPress?’ is closed to new replies.