• 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/

    <?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
    ID,post_title,post_content FROM $wpdb->posts<br />
    WHERE
    post_status= \"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=4

    If anyone could help me out with what to do or point me in the right direction it would be tremendously appreciated-

Viewing 1 replies (of 1 total)
  • Thread Starter mactoph

    (@mactoph)

    I finally found some help- this is the code that worked for me:

    <?php
    $how_many=4; //How many posts do you want to show
    $category=3; //Category you want to show
    require_once(“/path/to/blog/wp-config.php”); // Change this for your path to wp-config.php file
    ?>

    <?php
    query_posts(“cat={$category}&showposts={$how_many}”);
    if(have_posts()) { while(have_posts()) : the_post();
    echo “<h2>” . get_the_title() . “</h2>”;
    echo “” . get_the_content() . “”;
    endwhile;
    }
    ?>

    Thanks masquerade!

Viewing 1 replies (of 1 total)
  • The topic ‘Posts from one category outside of WordPress?’ is closed to new replies.