I’m building my site on a subdomain.
I am using a php include to reference a html file which is in the root folder, like this:
<?php include ABSPATH.'myfile.html';?>
I’ve also tried this:
<?php include ‘myfile.html’;?>
If I am using default permalinks, it works great
If I choose any of the other permalinks settings, it only works on whichever page I have set to be the static front page. All other pages just leave a space where the included file should be.
Can anyone please help me?
Cheers x
]]><?php
include 'somefile.inc.php';
?>
and save the draft. When I preview the page in Twenty Eleven, the code shows as text. When I go bak to the HTML I find that a space has been inserted in front of the question mark < ?php, making it invalid.
I can’t figure out why–is it the HTML editor or the theme that is doing this?
https://www.ads-software.com/extend/themes/twentyeleven/
]]>I also have “Allow PHP in Posts and Pages” plugin installed and know it’s working because I can echo a string into a page.
But, for some reason, the combination of the two are not working. I cannot echo a price variable from the included price list into a WordPress-generated page.
Does anyone have any ideas as to what I might be doing wrong?
]]>I’m trying to use a snippet I found on this post display post count to make a list of tags used (wrapped in a hrefs) the amount they are used and display it in my sidebar.
Here is a link to my site, the Tags section is near the bottom of the sidebar gtsb
The snippet I found that user and moderator Mark / t31os posted on that topic is this:
<?php
// Select all the post tag IDs
$the_tags = $wpdb->get_col("SELECT term_id
FROM $wpdb->term_taxonomy WHERE taxonomy = 'post_tag'" );
// Loop over each ID, and grab associated data
foreach($the_tags as $tag_id) {
// Get information on the post tag
$post_tag = get_term( $tag_id, 'post_tag' );
// Print the tag name and count (how many posts have this tag)
echo $post_tag->name.' ( '.$post_tag->count.' ) ';
// Unset the data when it's not needed
unset($post_tag);
}
?>
I did a minor visual adjustment to the brackets and wrapped it in this:
<div class="sbtags">
<?php
// Select all the post tag IDs
$the_tags = $wpdb->get_col("SELECT term_id
FROM $wpdb->term_taxonomy WHERE taxonomy = 'post_tag'" );
// Loop over each ID, and grab associated data
foreach($the_tags as $tag_id) {
// Get information on the post tag
$post_tag = get_term( $tag_id, 'post_tag' );
// Print the tag name and count (how many posts have this tag)
echo $post_tag->name.'<span>('.$post_tag->count.')</span>';
// Unset the data when it's not needed
unset($post_tag);
}
?>
Thanks in advance for any help!
]]>I have a website at https://jadebaltimore.com and I’m trying to customize The Francis Wright WP theme to look like my site. You can view the theme here: https://www.ads-software.com/extend/themes/the-frances-wright.
Since I’m really only trying to add my navigation bar to the theme (everything else is fine the way it is), I read that I could do that as a PHP include. Unfortunately, I haven’t encountered any directions on how this is typically done, so I tried to wing it to no avail. I’ll walk you through the steps I took and if you have any insight into what I’m doing wrong, I could really use your advice.
First, I opened a PHP doc in Dreamweaver CS5.5, inserted a Spry Menu Bar, and styled it to look exactly like my existing menu bar at jadebaltimore.com. I then saved the file in the “includes” folder of my test site, which I’ve been testing on my local server. I named the file “menubar.inc.php.” I tested it out in Firefox and everything looked great.
Next, I attempted to load it on my WP theme by moving the “menubar.inc.php” file to the “includes” folder of my WP blog. I also copied the Spry Assets folder into my blog’s theme folder because I assumed the nav bar would have to pull from it in order to load properly.
Finally, I copied the php includes code and pasted it in my theme’s header file. You can view the codes below.
“menubar.inc.php code:
<div id="navigation"><?php include('includes/menubar.inc.php'); ?></div>
<map name="Map4" id="Map4">
<area shape="rect" coords="113,343,212,377" href="bio.html" alt="Bio" />
<area shape="rect" coords="110,388,241,424" href="poetry.html" />
<area shape="rect" coords="110,430,333,468" href="nonfiction.html" />
<area shape="rect" coords="113,475,275,510" href="fiction.html" alt="Fiction" />
<area shape="rect" coords="113,518,236,555" href="https://www.jadebaltimore.com/blog" alt="Blog" />
<area shape="rect" coords="111,563,264,594" href="resume.html" alt="Resume" />
</map>
My theme’s header code:
<?php
/**
* @package WordPress
* @subpackage TheFrancesWright
*/
?>
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="https://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta name="viewport" content="inital-scale=1.0, width=device-width" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
wp_title( '|', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
echo " | $site_description";
}
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 ) {
echo ' | ' . sprintf( __( 'Page %s', 'themesweet' ), max( $paged, $page ) );
}
?></title>
<link rel="profile" href="https://gmpg.org/xfn/11" />
<?php wp_enqueue_style('google_fonts', 'https://fonts.googleapis.com/css?family=Meddon|Ubuntu:300|Raleway:100|PT+Serif'); ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<body lang="en">
<div id="site">
<div id="content">
<div id="menu">
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
</div>
<a href="<?php echo home_url(); ?>">
<div id="lockup">
<div id="headimg"></div>
<h1 id="site_title">
<?php bloginfo('name'); ?>
</h1>
<i id="tagline"><?php bloginfo( 'description' ); ?></i>
</div>
</a>
I tried placing the php include code between these two codes in the header file:
<?php wp_head(); ?>
</head>
And, when that didn’t work, I tried placing it between these two codes in the header file:
</head>
<body <?php body_class(); ?>>
So far, nothing has worked. I’m not even sure I have the “menubar.inc.php” file or the Spry Assets folder in the right place. Can someone please, please, please explain what I’m doing wrong? I’ve spent months working on this project and I’m at my wit’s end. I’ve tried everything I can think of and I just can’t seem to make it work. Any help would be greatly appreciated!
]]>I would like to display a message on my site that I will change occasionally. I thought it may be best to do this through a post that I occasionally edit the copy on. I want this message on every page so I plan to put it in my header.php.
I’m not sure what function and parameters to call for this. I’ve tried:
<?php query_posts('p=5'); ?>
Am I on the right track or is this the wrong way of doing this?
Thanks in advance!
]]>Goal:
Add a simple php include in a post and have it actually work.
Issue:
I used to use simple php includes in custom websites, but when I put php include code in a post, it nullifies the php code.
Is there a proper way to add php include code in a WP post or should one use a PHP include plugin to get the job done? ( I know there’s a few out there, but wanted to make sure that was the route to go before implementing a plugin)
Thanks for your guidance!
]]>I have tried both of the following in the pages, edit feature.
<?php include(“nav.php”); ?>
{require_once(‘nav.php’);}
did not work any suggestions are appreciated
]]>