503 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Trying to add a automatic importer into WP e.g.

File is called rss-pc-world.php, now I want to include this on a WP page called pc-world.

I would use the following code normally

   <?php include(ABSPATH . './wp-content/themes/voucher-wp/rss-pc-world'); ?>

BUT I want to be able to do this automatically, I would build the PHP files but I want the above code to grab the file which has the same name as the page, I know I would use wp-title but not sure on how to include it in the above code.

I have tried the following:

   <?php include(ABSPATH . './wp-content/themes/voucher-wp/rss-'.wp-title().'.php'); ?>

This doesn’t work, can anyone help with this?

Thanks

741 posts
  • Has been a member for 5-6 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Poland
  • Referred between 10 and 49 users
Orbital_Themes says

Well, to use wp_title() like this you’d have to do it like that:

wp_title( "", false )

I don’t know what you are trying to do but I can tell you it’s not a good practice.

503 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Well, to use wp_title() like this you’d have to do it like that: wp_title( "", false ) I don’t know what you are trying to do but I can tell you it’s not a good practice.

How would you do it then? I need to include a different file on each page, the file included will be the same as the slug for the page e.g.

rss-pc-world.php would be included in mydomain.com/pc-world/

1237 posts
  • Interviewed on the Envato Notes blog
  • Won a Competition
  • Halloween Competition Winner
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • United Kingdom
LoveThemes says
<?php 
global $post;
include(ABSPATH . './wp-content/themes/voucher-wp/rss-'.$post->post_name.'.php'); ?>
?>
503 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

<?php 
global $post;
include(ABSPATH . './wp-content/themes/voucher-wp/rss-'.$post->post_name.'.php'); ?>
?>

Ta very much, works a treat :)

1237 posts
  • Interviewed on the Envato Notes blog
  • Won a Competition
  • Halloween Competition Winner
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • United Kingdom
LoveThemes says

No problem.

by
by
by
by
by
by