Struggling- php includes wp-load for showing search results in a page
-
My website is html, but I have a wordpress instalation in a folder /blog. I have landing pages for a few different subjects that I’d like to display search results for from my wordpress posts. (I’m hoping here that by using ‘includes’ Google will see this as a valid set of links, but I’ll always know it’s up to date without having to keep updating the page?)
Like I say, My site is html, but I’ve already tweaked it to run php, and in fact my menus load using <?php include(‘../../includes/sidemenu.htm’); ?> so I know that php commands can run on there OK. For some reason though I can’t get any guides I’ve found for including search WP results, to display anything at all. In fact the page cuts short and anything after the php fails to load while it’s there.
What I’ve tried is placing the following where I want the lists to show:
(Lifted straight from here)<?php // Include the wp-load'er include('/blog/wp-load.php'); // Get the last 10 posts // Returns posts as arrays instead of get_posts' objects $recent_posts = wp_get_recent_posts(array( 'numberposts' => 10 )); // Do something with them echo '<ul>'; foreach($recent_posts as $post) { echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>'; } echo '</ul>'; ?>
Though once I get that working I hoped to change it to search for a particular string, rather than just display the 10 newest. But for starters I can’t find why it won’t display anything
- The topic ‘Struggling- php includes wp-load for showing search results in a page’ is closed to new replies.