开发者

Putting a Wordpress post feed into a <select> dropdown

开发者 https://www.devze.com 2023-02-25 14:45 出处:网络
Good afternoon all! I\'ve tried sever开发者_开发知识库al different options here but am at my wits end with this:

Good afternoon all! I've tried sever开发者_开发知识库al different options here but am at my wits end with this:

I'm working on an older site that has static .php pages. The owner needs a wordpress installation created in a sub folder.... no problem.

However, I need a menu on the static home page as well as some static sub pages that have the following menu:

Postname

Any ideas how i can dynamically generate this menu on the static pages from the wordpress feed?


If you're comfortable running some quick and dirty MySQL on the PHP pages, you could do a query to get a list of the pages:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Create database query
$query = "SELECT ID, post_title, post_name, guid FROM wp_posts WHERE post_status='publish' AND post_type='page'";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
    // create <select/> based on database results
}
?>

You would need to use JavaScript to make the dropdown jump to each page as required, which leads me to my next point. This method is not good for SEO and it also relies on users having JavaScript enabled in order for it to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号