PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Here's the PHP code that is supposed to be used to determine which links will be shown on the page, being the query link or the pretty link. Here's the PHP:
This is a website based on word press, so that when the "permalink" or "pretty" link setting is on it's supposed to display the pretty link. When the permalink setting is off it's displaying the query link which is working correctly. You can view the page here: http://www.songlyricsx.com/lyrics/a/, how it's saying page 1 of 1, etc, those are the links I'm trying to fix. Thanks!
<?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
//the variables would be something like:
if ( is_category('3') ) {
$parent = 3;// your category parent ID
$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 = '3'";
} elseif ( is_category('4') ) {
$parent = 4;
$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 = '4'";
} elseif ( is_category('5') ) {
$parent = 5;
$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 = '5'";
} elseif ( is_category('6') ) {
$parent = 6;
$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 = '6'";
} elseif ( is_category('7') ) {
$parent = 7;
$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 = '7'";
} elseif ( is_category('8') ) {
$parent = 8;
$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 = '8'";
} elseif ( is_category('9') ) {
$parent = 9;
$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'";
} elseif ( is_category('10') ) {
$parent = 10;
$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 = '10'";
} elseif ( is_category('11') ) {
$parent = 11;
$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 = '11'";
} elseif ( is_category('12') ) {
$parent = 12;
$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 = '12'";
} elseif ( is_category('13') ) {
$parent = 13;
$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 = '13'";
} elseif ( is_category('14') ) {
$parent = 14;
$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 = '14'";
} elseif ( is_category('15') ) {
$parent = 15;
$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 = '15'";
} elseif ( is_category('16') ) {
$parent = 16;
$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 = '16'";
} elseif ( is_category('17') ) {
$parent = 17;
$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 = '17'";
} elseif ( is_category('18') ) {
$parent = 18;
$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 = '18'";
} elseif ( is_category('19') ) {
$parent = 19;
$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 = '19'";
} elseif ( is_category('20') ) {
$parent = 20;
$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 = '20'";
} elseif ( is_category('21') ) {
$parent = 21;
$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 = '21'";
} elseif ( is_category('22') ) {
$parent = 22;
$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 = '22'";
} elseif ( is_category('23') ) {
$parent = 23;
$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 = '23'";
} elseif ( is_category('24') ) {
$parent = 24;
$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 = '24'";
} elseif ( is_category('25') ) {
$parent = 25;
$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 = '25'";
} elseif ( is_category('26') ) {
$parent = 26;
$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 = '26'";
} elseif ( is_category('27') ) {
$parent = 27;
$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 = '27'";
} elseif ( is_category('28') ) {
$parent = 28;
$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 = '28'";
} elseif ( is_category('31') ) {
$parent = 31;
$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 = '31'";
}
$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 = 1; //Limit the result to 20, change this to your need $paginate = new sitePagination($page,$perPage,$num_rows);
$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 "<br /><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().'">« Previous</a>'; else echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->previousPage().'">« Previous</a>';
}else{
echo '<a href="?cat='.$cat_parent->term_id.'¤t_page='.$paginate->previousPage().'">« 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='.$cat_parent->term_id.'¤t_page='.$i.'">'.$i.'</a>';
}
}
if($paginate->totalPages() > 1){
if($paginate->nextPageExists()){
if ( get_option('permalink_structure') ){
if($page)
echo '<a href="'.$paginate->nextPage().'">Next »</a>'; else
echo '<a href="'.$cat_parent->slug.'/page/'.$paginate->nextPage().'">Next »</a>'; }else{
echo '<a href="?cat='.$cat_parent->term_id.'¤t_page='.$paginate->nextPage().'">Next »</a>';
}
}
}
echo "</div>";
} else { ?>
<!-- post loop -->
<?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 »', '1 Comment »', '% Comments »'); ?> <?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 »'); ?> </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('« Previous Entries') ?></div> <div class="alignright"><?php previous_posts_link('Next Entries »') ?></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(); ?>