Hi everyone. I have a website setup and want to add a blog to the site. On my navigation bar i want to have a link to the main (say we call it index.php) page of my blog. I have installed wordpress v3 successful in a folder named blog in the root dir of my site (). I added blog to nav bar but are stuck how to make it a link (link to my blog). Any helpl/tutorial would be appreciated.

Dani AI

Generated

Quick follow-up for — glad 's nav hint got the link working. To show posts/comments from your WordPress blog on your site index there are three practical approaches. Pick the one that matches how tightly you want to couple the two sites and how much control you need over markup.

  1. Load WordPress and use WP functions (tight coupling, full control)
// from your index.php (adjust path)
require_once __DIR__ . '/blog/wp-load.php';

$posts = get_posts(array('numberposts' => 3, 'post_status' => 'publish'));
foreach ($posts as $post) {
    setup_postdata($post);
    echo '<h2>' . esc_html(get_the_title($post)) . '</h2>';
    echo apply_filters('the_excerpt', $post->post_excerpt ?: wp_trim_words($post->post_content, 30));
    echo '<p>' . intval(get_comments_number($post)) . ' comments</p>';
}
wp_reset_postdata();

Pros: full access to WP API (comments via get_comments()). Cons: couples code to WP, possible function collisions, and extra load — use transients or another cache.

  1. Use the WordPress REST API (decoupled, modern)
fetch('/blog/wp-json/wp/v2/posts?per_page=3')
  .then(r => r.json())
  .then(posts => {
    const html = posts.map(p => `<article><h2>${p.title.rendered}</h2>${p.excerpt.rendered}</article>`).join('');
    document.getElementById('blog-snippet').innerHTML = html;
  });

Comments: fetch comments with /wp-json/wp/v2/comments?post=ID. If the blog is same-origin you avoid CORS; otherwise enable CORS or proxy server-side. Sanitize or trust WP-rendered HTML appropriately.

  1. Parse the RSS feed (simple, read-only)
$xml = simplexml_load_file('/blog/feed/');
foreach ($xml->channel->item as $item) {
  echo '<h3>' . htmlspecialchars($item->title) . '</h3>';
  echo '<p>' . strip_tags($item->description) . '</p>';
}

Good for headlines/excerpts; comments are usually not available.

Notes and cautions: always escape/sanitize output (esc_html, wp_kses, htmlspecialchars), cache results to avoid slow page loads, watch include paths so you don't accidentally load WP twice, and avoid exposing private content (authentication needed for private posts via the API). is right that the documentation is useful — the examples above are practical shortcuts you can apply immediately depending on whether you want tight integration (option 1), a modern decoupled approach (option 2), or a minimal read-only feed (option 3).

Recommended Answers

All 4 Replies

Just make a link to your blog folder.

<a href="/blog/">Read my blog</a>

hey magicmedia your suggestion worked fine. my next question is how do i display post/comments of my blog on the index page of my website. thanks.

hey magicmedia your suggestion worked fine. my next question is how do i display post/comments of my blog on the index page of my website. thanks.

Or you could, you know, read the documentation and find out yourself?

http://codex.wordpress.org/

You'll thank me later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.