lukemv
Member
Posted 11 months ago #
I have a PHP page that sits outside of the WordPress pages... (same directory as WP-Content). Within this PHP page, I wanted to list the blog posts whose tags include "XYZ". Can anyone provide me the code that I can use to list these posts within this PHP code and link to them?
lukemv
Member
Posted 11 months ago #
Does this matter that my blog isn't in a subdirectory, but instead the pages are within what would be the sub directory's folder? ie: in the same directory as the folder 'wp-content'?
lukemv
Member
Posted 11 months ago #
Using
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
Kills the page, without an error.
why don't you create a page template then use the query_posts() function to modify the loop to get the posts you want?
lukemv
Member
Posted 11 months ago #
Because it is outside of the wordpress folder.
the page template should be in the theme folder anyway.
the fundamental question is why you're creating a separate PHP page outside wordpress to pull data from the wordpress database, instead of just making use of features within the wordpress system to accomplish your task.
lukemv
Member
Posted 11 months ago #
The primary reason is because I am using .htaccess (see code below) to rewrite the URL names for SEO.... the URLs are: URL.com/some_name_here_i123.html and it goes to URL.com/i.php, pulling the ID from $i and then dynamically populating the page from separate mySQL database.
Previously, I had tried to have the same thing happen within a file in the WordPress theme directory, but it was having some conflicts the last time I tried and didn't want to risk breaking it...
Thoughts?
HTACCESS
<IfModule mod_rewrite.c>
RewriteRule ^([^-]+)-([^&]+).html /i.php?id=$1&id=$2 [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
but wordpress already does this automatically.
URL.com/tags/tag-name
lukemv
Member
Posted 11 months ago #
Obviously, but that is besides the point. I am not looking for a workaround to this. I am looking for making the code work outside of the theme folder—in the root folder for the WordPress theme.
lukemv
Member
Posted 11 months ago #
Here is the correct code to do what I am trying to do:
<?php require( 'path/to/wp-load.php' ); ?>