Page 1 of 1

Syntax Help

Posted: Fri Feb 12, 2010 7:16 pm
by gward1
Hello,

I have some code and I keep getting a syntax error "parse error, unexpected '(', expecting '}' in category.php on line 53"

You can view the entire code here:

Code: Select all

 
<?php get_header(); ?>
<?php get_sidebar(); ?>
    <div class="middle">
<?php
if ( is_category() ) {
  $cat = get_query_var('cat');
  $child_cats = get_categories('child_of='.$cat);
  if ($child_cats) {
 
    //include the paginate class. I put it in the theme folder
 
    include("paginate.php");
 
 
 
    // This is the SQL Query to get the number of rows I have
 
 
 
    $count = "SELECT COUNT(*) FROM $wpdb->terms AS t
            INNER JOIN $wpdb->term_taxonomy AS tt
            ON t.term_id = tt.term_id WHERE tt.taxonomy IN('category') AND tt.parent = '9'";
 
 
    $number =  mysql_query($count);
                
    $row = mysql_fetch_array($number);
                
    $num_rows = array_shift($row);
 
                
 
    // Define some variable to hold our pagination settings
 
    $page = !empty($_GET['current_page']) ? (int)$_GET['current_page'] : 1;
    $perPage = 20; //Limit the result to 20, change this to your need
    $paginate  =  new sitePagination($page,$perPage,$num_rows);
 
    //the variables would be something like:
    $parent = 9;// your category parent ID
 
    $where = " tt.parent = '$parent'";
    $in_taxonomies = 'taxonomy';
    $orderby = 't.term_id';
    $order = 'ASC';
 
    //This is the actual SQL Query to fetch the Data from Database
 
    $query = "SELECT * FROM $wpdb->terms AS t
            INNER JOIN $wpdb->term_taxonomy AS tt
            ON t.term_id = tt.term_id WHERE tt.taxonomy IN('category')
             AND tt.parent = '$parent' LIMIT {$perPage} OFFSET {$paginate->offset()}";
            
    $terms = $wpdb->get_results($query);
 
    // A foreach loop to output the data nice and clean
 
 
    foreach($terms as $term)
 
    {
 
        $cat_parent = get_category($term->parent);
 
 
        //Had to use the $cat_parent to build the link
 
        //if some has a better idea, would be nice
 
 
        echo "<li><a href='".$cat_parent->slug.'/'.$term->slug."'>". $term->name ."</a></li>";
 
    }
 
    // The Fun starts here, all the code below will generate our dynamic page number
 
    // The container css class is the same as WP PAGENAVI
    // I'm using a custom pagination class I created
 
 
    echo "<div class='wp-pagenavi'>";
 
    echo "<span class='pages'>Page {$page} of {$paginate->totalPages()}</span>";
 
    if($paginate->totalPages() > 1){
        if($paginate->previousPageExists()){
 
            if ( get_option('permalink_structure') ){
                if($page)
 
                    echo '<a href="'.$paginate->previousPage().'">&laquo; Previous</a>';
                else
                    echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->previousPage().'">&laquo; Previous</a>';
 
                }else{
 
                    echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->previousPage().'">&laquo; Previous</a>';
                }
 
        }
    }
 
 
    for($i=1;$i < ceil($paginate->totalPages()) + 1;$i++){
        if($page == $i)
 
            echo '<span class="current">'.$i.'</span>';
        else
            if ( get_option('permalink_structure') ){
                if($page)
                    echo '<a href="'.$i.'">'.$i.'</a>';
                else
 
                echo '<a href="'.$cat_parent->slug.'/page/'.$i.'">'.$i.'</a>';
            }else{
                echo '<a href="'.$cat_parent->slug.'/?current_page='.$i.'">'.$i.'</a>';
            }
    }
 
 
    if($paginate->totalPages() > 1){
 
        if($paginate->nextPageExists()){
            if ( get_option('permalink_structure') ){
 
                if($page)
 
                    echo '<a href="'.$paginate->nextPage().'">Next &raquo;</a>';
                else
 
                    echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->nextPage().'">Next &raquo;</a>';
            }else{
 
                echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->nextPage().'">Next &raquo;</a>';
 
            }
 
        }
 
    }
 
 
    echo "</div>";
    );
  } else { ?>
        <?php if (have_posts()) : ?>
 
        <?php while (have_posts()) : the_post(); ?>
 
            <div id="post-<?php the_ID(); ?>">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <p><small><?php the_time('F jS, Y') ?> <?php the_author() ?></small> Posted in <?php the_category(', ') ?> <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', '', ' | '); ?> <?php if(function_exists('the_views')) { the_views(); } ?></p>
 
                <div class="entry">
                    <?php the_content('Read the rest of this entry &raquo;'); ?>
                </div>
                
                <br />
 
 
    <!-- AddThis Bookmark Post Button BEGIN -->
<?php echo "<div class=\"addthis\"><a href=\"http://www.addthis.com/bookmark.php?pub=blogohblog&url=".get_permalink()."&title=".get_the_title($id)."\" title=\"Bookmark using any bookmark manager!\" target=\"_blank\"><img src=\"http://s9.addthis.com/button1-bm.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"AddThis Social Bookmark Button\" /></a></div>"; ?>
<!-- AddThis Bookmark Post Button END -->
            </div>
<div class="br"><br /></div>
        <?php endwhile; ?>
 
        <div>
            <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
            <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
        </div>
<br />
    <?php else : ?>
 
        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
<?php
  }
}
?>
    </div>
 
<?php get_sidebar(); ?>
 
<?php get_footer(); ?>
 
Any assistance is greatly appreciated.

Re: Syntax Help

Posted: Fri Feb 12, 2010 7:33 pm
by Eran
you can't place a method call inside a string like you did on that line. Store the method return value in a variable, and use that variable inside the string instead

Incorrect:

Code: Select all

$query = "SELECT ... {$paginate->offset()}";
Correct:

Code: Select all

$offset = $paginate -> offset();
$query = "SELECT ... {$offset}";

Re: Syntax Help

Posted: Sat Feb 13, 2010 2:46 am
by gward1
Thanks for the help, that fixed the issue. There was another line I was able to fix However I'm getting 2 more errors. parse error, unexpected ')' in category.php on line 146 and parse error, unexpected '}' in category.php on line 182. I was able to fix the error on line 146 by replacing it with a } which is what looks like is supposed to go there but I have no idea what the problem is on line 181.

Code: Select all

 
<?php get_header(); ?>
<?php get_sidebar(); ?>
    <div class="middle">
<?php
if ( is_category() ) {
  $cat = get_query_var('cat');
  $child_cats = get_categories('child_of='.$cat);
  if ($child_cats) {
 
    //include the paginate class. I put it in the theme folder
 
    include("paginate.php");
 
 
 
    // This is the SQL Query to get the number of rows I have
 
 
 
    $count = "SELECT COUNT(*) FROM $wpdb->terms AS t
            INNER JOIN $wpdb->term_taxonomy AS tt
            ON t.term_id = tt.term_id WHERE tt.taxonomy IN('category') AND tt.parent = '9'";
 
 
    $number =  mysql_query($count);
                
    $row = mysql_fetch_array($number);
                
    $num_rows = array_shift($row);
 
                
 
    // Define some variable to hold our pagination settings
 
    $page = !empty($_GET['current_page']) ? (int)$_GET['current_page'] : 1;
    $perPage = 20; //Limit the result to 20, change this to your need
    $paginate  =  new sitePagination($page,$perPage,$num_rows);
 
    //the variables would be something like:
    $parent = 9;// your category parent ID
 
    $where = " tt.parent = '$parent'";
    $in_taxonomies = 'taxonomy';
    $orderby = 't.term_id';
    $order = 'ASC';
 
    //This is the actual SQL Query to fetch the Data from Database
    
    $offset = $paginate -> offset();
    $query = "SELECT * FROM $wpdb->terms AS t
            INNER JOIN $wpdb->term_taxonomy AS tt
            ON t.term_id = tt.term_id WHERE tt.taxonomy IN('category')
             AND tt.parent = '$parent' LIMIT {$perPage} OFFSET {$offset}";
            
    $terms = $wpdb->get_results($query);
 
    // A foreach loop to output the data nice and clean
 
 
    foreach($terms as $term)
 
    {
 
        $cat_parent = get_category($term->parent);
 
 
        //Had to use the $cat_parent to build the link
 
        //if some has a better idea, would be nice
 
 
        echo "<li><a href='".$cat_parent->slug.'/'.$term->slug."'>". $term->name ."</a></li>";
 
    }
 
    // The Fun starts here, all the code below will generate our dynamic page number
 
    // The container css class is the same as WP PAGENAVI
    // I'm using a custom pagination class I created
 
 
    echo "<div class='wp-pagenavi'>";
    $totalPages = $paginate -> totalPages();
    echo "<span class='pages'>Page {$page} of {$totalPages}</span>";
 
    if($paginate->totalPages() > 1){
        if($paginate->previousPageExists()){
 
            if ( get_option('permalink_structure') ){
                if($page)
 
                    echo '<a href="'.$paginate->previousPage().'">&laquo; Previous</a>';
                else
                    echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->previousPage().'">&laquo; Previous</a>';
 
                }else{
 
                    echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->previousPage().'">&laquo; Previous</a>';
                }
 
        }
    }
 
 
    for($i=1;$i < ceil($paginate->totalPages()) + 1;$i++){
        if($page == $i)
 
            echo '<span class="current">'.$i.'</span>';
        else
            if ( get_option('permalink_structure') ){
                if($page)
                    echo '<a href="'.$i.'">'.$i.'</a>';
                else
 
                echo '<a href="'.$cat_parent->slug.'/page/'.$i.'">'.$i.'</a>';
            }else{
                echo '<a href="'.$cat_parent->slug.'/?current_page='.$i.'">'.$i.'</a>';
            }
    }
 
 
    if($paginate->totalPages() > 1){
 
        if($paginate->nextPageExists()){
            if ( get_option('permalink_structure') ){
 
                if($page)
 
                    echo '<a href="'.$paginate->nextPage().'">Next &raquo;</a>';
                else
 
                    echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->nextPage().'">Next &raquo;</a>';
            }else{
 
                echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->nextPage().'">Next &raquo;</a>';
 
            }
 
        }
 
    }
 
 
    echo "</div>";
    );
      } else { ?>
        <?php if (have_posts()) : ?>
 
        <?php while (have_posts()) : the_post(); ?>
 
            <div id="post-<?php the_ID(); ?>">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <p><small><?php the_time('F jS, Y') ?> <?php the_author() ?></small> Posted in <?php the_category(', ') ?> <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', '', ' | '); ?> <?php if(function_exists('the_views')) { the_views(); } ?></p>
 
                <div class="entry">
                    <?php the_content('Read the rest of this entry &raquo;'); ?>
                </div>
                
                <br />
 
 
    <!-- AddThis Bookmark Post Button BEGIN -->
<?php echo "<div class=\"addthis\"><a href=\"http://www.addthis.com/bookmark.php?pub=blogohblog&url=".get_permalink()."&title=".get_the_title($id)."\" title=\"Bookmark using any bookmark manager!\" target=\"_blank\"><img src=\"http://s9.addthis.com/button1-bm.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"AddThis Social Bookmark Button\" /></a></div>"; ?>
<!-- AddThis Bookmark Post Button END -->
            </div>
<div class="br"><br /></div>
        <?php endwhile; ?>
 
        <div>
            <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
            <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
        </div>
<br />
    <?php else : ?>
 
        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
<?php
  }
}
?>
    </div>
 
<?php get_sidebar(); ?>
 
<?php get_footer(); ?>
 
Thanks again.

Re: Syntax Help

Posted: Sat Feb 13, 2010 6:23 pm
by gward1
bump