Forum Moderators: coopster

Message Too Old, No Replies

Problem with Custom Script

PHP4 vs. PHP5?

         

doodlebee

3:21 pm on May 15, 2007 (gmt 0)

10+ Year Member



I have written a custom script for a client of mine, for use with a new WordPress theme. On my localhost server (which is running MySQL5/PHP5) it works perfectly. But when I upload it to my live server via webhost (running MySQL4/PHP4), it does not.

My gut feeling is that the reason it's not working on the live server is because it's on PHP4, and it's written for PHP5. I can't see what I need to "fix" to make it run on both types (really, I need it to run on PHP4 right now more than PHP5), so could someone take a peek here and let me know what I can do to fix it?


<?php

function client_page_links() {

$default_sort = 'ID';
$allowed_order = array ('ID', 'page_id', 'post_title');

if (!isset ($_GET['order']) ¦¦
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}

$query = "SELECT * FROM wp_options, wp_posts, wp_postmeta where option_name = 'siteurl' AND meta_key = 'main_nav_description' AND post_id = wp_posts.ID ORDER by $order" or die(mysql_error());
$result = mysql_query ($query);

$currenttitle = "";
$pausetitle = "What we do";
$line_num = 1;

while ($row = mysql_fetch_assoc($result)) {

$siteurl = $row['option_value'] . "/";

if ($row['post_title']!= $currenttitle) {

//echo $line_num . "\n" . $row['post_title'] . "\n" . $row['meta_value'] . "<br />";

echo "<li class=\"clear\"><a href=\"" . $siteurl . $row['post_name'] . "\" title=\"" . $row['post_title'] . "\" >" . "\n";
echo "<span class=\"sidebox\"><strong>" . $line_num . "</strong></span>" . "\n";
echo "<span class=\"linkname\"><span class=\"sidetitle\">" . $row['post_title'] . "</span>" . "\n";
echo "<span class=\"sidedesc\">" . $row['meta_value'] . "</span></span></a></li>" . "\n\n";

}

if ($row['post_title'] == $pausetitle) {

$line_num++;

echo "<li class=\"clear\"><a href=\"" . $siteurl . "category/industry-articles\" title=\"Industry Articles\" >" . "\n";
echo "<span class=\"sidebox\"><strong>" . $line_num . "</strong></span>" . "\n";
echo "<span class=\"linkname\"><span class=\"sidetitle\">Industry Articles</span>" . "\n";
echo "<span class=\"sidedesc\">Useful Information</span></span></a></li>" . "\n\n";
}

$currenttitle = $row['post_title'];
$line_num++;

}

}


function client_post_layout() {?>
<div class="post" id="post-<?php the_ID();?>">

<h1><a href="<?php the_permalink()?>" rel="bookmark" title="Permanent Link to <?php the_title();?>"><?php the_title();?></a></h1>

<h2>by <?php the_author()?></h2>

<div class="entry">

<?php the_content('Read more &raquo;');?>

</div> <!-- /entry -->

<p class="postmetadata"><?php the_time('F jS, Y')?> &nbsp; <?php the_time('g:i a')?> &nbsp; <?php comments_popup_link('No Comments', 'Comment (1)', 'Comments (%)');?></p>

</div> <!-- /post -->
<? }


function client_callout_boxes() {?>
<div class="callout">

<div class="tr"><div class="tl"><div class="br"><div class="bl">
<div class="boxcontent">
<div class="bt">
<?php the_excerpt_reloaded(12, '', '', TRUE, 'find out more &raquo;', FALSE, 1, TRUE);?>
</div>
</div>
</div></div></div></div>

</div> <!-- /callout -->

<? }


function client_inherit_template() {

if (is_category()) {
$catid = get_query_var('cat');

if ( file_exists(TEMPLATEPATH . '/category-' . $catid . '.php') ) {
include( TEMPLATEPATH . '/category-' . $catid . '.php');
exit;
}

$cat = &get_category($catid);
$parent = $cat->category_parent;

while ($parent){
$cat = &get_category($parent);
if ( file_exists(TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php') ) {
include (TEMPLATEPATH . '/category-' . $cat->cat_ID . '.php');
exit;
}
$parent = $cat->category_parent;
}
}

}

add_action('template_redirect', 'client_inherit_template', 1);

?>

Now, when I call in these functions (aside from the last one, which gets plugged into a ready-made tag), I'm using client_page_links(), client_callout_boxes() and so on where I need them to appear. As I said, on my localhost, this works perfectly. But on the live server, it acts as if the information I'm pulling is in nothing but blank white space. The site appears, just the content that's supposed to show does not.

Would anyone have any ideas/suggestions for me?

mcibor

4:05 pm on May 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. First mistake is in the mysql
SELECT * FROM wp_options, wp_posts, wp_postmeta where option_name = 'siteurl' AND meta_key = 'main_nav_description' AND post_id = wp_posts.ID ORDER by $order

$order is 'ID' - in which table? The same with WHERE - specify all tables

2. Second mistake is in the same line. It should be:
$query = "SELECT * FROM wp_options, wp_posts, wp_postmeta where option_name = 'siteurl' AND meta_key = 'main_nav_description' AND post_id = wp_posts.ID ORDER by $order";
$result = mysql_query ($query) or die(mysql_error());

3. What is the_permalink()? It's not defined anywhere
the_title()?
the_time('F jS, Y')?
comments_popup_link('No Comments', 'Comment (1)', 'Comments (%)')
get_query_var()

5. Here's another mistake
$cat = &get_category($catid);
$parent = $cat->category_parent;

You haven't declared this class anywhere

6. You have a strange mixture of template and echo...

set
error_reporting(E_ALL);

and see the mistakes.

Then we may be of help.
Michal

PS. I am too good (in behaviour) for newbies :D

doodlebee

4:35 pm on May 15, 2007 (gmt 0)

10+ Year Member



$result = mysql_query ($query) or die(mysql_error());

Thanks for that - my bad ;)

3. What is the_permalink()? It's not defined anywhere
the_title()?
the_time('F jS, Y')?
comments_popup_link('No Comments', 'Comment (1)', 'Comments (%)')
get_query_var()

and


Here's another mistake
$cat = &get_category($catid);
$parent = $cat->category_parent;

Doesn't need to be in the script. The script is a file that based within the WordPress system and those varibales are calling on the Wordpress system to pull in the info. These variables set and ready to be queried when needed - by the above statements. The ones you're asking about *are* defined - just in other files.

You have a strange mixture of template and echo...

I guess by looking at this, you would think so. But it *is* this way for a reason.

I'll see what I can do on the rest...

and my error reporting is already on, by the way. No errors are showing up - not even in my logs.

EDIT: also, I guess I should say that wp_options, wp_posts, wp_postmeta are three different tables. "option_name" is from the "wp_options" table. The rest (meta_key and post_ID) go with wp_postmeta.

doodlebee

5:15 pm on May 15, 2007 (gmt 0)

10+ Year Member



oh *DUH* - I know why it wasn't working.

The script is looking for the meta_key with a value of "main_nav_description". I forgot to set that - and since it can't find that value, it's not outputting anything.

Sorry - what a dumb mistake. (And now I know why no error messages were showing up - it was working fine! LOL)

But thanks - you got me looking at my fields to see what was going on!

mcibor

9:03 am on May 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it solved.

Logic mistakes are always the worst!

Regards
Michal