SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod_rewrite with custom script for friendly URLS

    Hello,

    I always built my own websites and classes. Now I want to use WordPress and use my own scripts in some cases.

    I have this script (it is already within a WordPress template):

    PHP Code:
      <?php
    /*
    Template Name: Page: Banden
    */
    $website "ty";
    ?>
            <script type="text/javascript" src="includes/js/jquery.js"></script>
            <script type="text/javascript" src="includes/js/jqueryUI.min.js"></script>
            <script type="text/javascript" src="includes/js/configuratie.js"></script>
    <?php get_header(); ?>

        <?php get_template_part'framework/inc/titlebar' ); ?>

        <div id="page-wrap" class="container">

            <div id="content" class="sixteen columns">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <article id="post-<?php the_ID(); ?><?php post_class(); ?>>

                    <div class="entry">
    <?php

        
    include_once "vars.php";
        include_once 
    "includes/inc/config.inc.php";
        include_once 
    "class/banden.class.php";
        
    $banden = new banden($dbo);
        if(isset(
    $zomer)){$zomer;}
        if(isset(
    $winter)){$winter;}
        if(isset(
    $allseason)){$allseason;}
        if(isset(
    $overig)){$overig;}
        
    $seasons = array("ZO"=>$zomer"WI"=>$winter"AS"=>$allseason"OV"=>$overig);
        isset(
    $seasons['ZO']);
        isset(
    $seasons['WI']);
        isset(
    $seasons['AS']);
        isset(
    $seasons['OV']);
        if(isset(
    $_GET['cat']) && isset($_GET['merk']))
        {
    ?>
                <table border="1" class="bandenmerken">
    <?php
        $tyres 
    $banden->getTyres($_GET['cat'], $_GET['merk']);
        
    $typearray = array();
        
    $counter 0;
        
    $start 0;
        foreach(
    $tyres as $tyre)
        {
            if(!
    in_array($tyre->uitvoeringvoertuigtype$typearray))
            {
                if(
    $start == 1)
                {
    ?>
                    </tr>
    <?php
                
    }
    ?>
    <?php
    if($tyre->uitvoeringvoertuigtype == "BW")
    {
    ?>
        </tr>
        </table>
        <table border="1" class="bandenmerken">

    <?php
    }
    ?>
    <?php
    if($tyre->uitvoeringvoertuigtype == "X4")
    {
    ?>

        </table>
        <table border="1" class="bandenmerken">

    <?php
    }
    ?>
                    <tr>
                        <th colspan="2"><?php
                
    switch($tyre->uitvoeringvoertuigtype)
                {
                    case 
    "AU":
                        echo 
    "Personenwagens";
                        break;
                    case 
    "BW":
                        if (isset(
    $deliveryvan)){ echo $deliveryvan;}
                        break;
                    case 
    "X4":
                        if (isset(
    $x4)){ echo $x4;}
                        break;
                    case 
    "TR":
                        if (isset(
    $truck)){ echo $truck;}
                        break;
                        echo 
    "";
                        break;
                }
    ?></th>
                    </tr>
                    <tr>
    <?php
                array_push
    ($typearray$tyre->uitvoeringvoertuigtype);
                
    $counter 0;
            }
            if(
    $counter == 2)
            {
    ?>
                    </tr>
                    <tr>
    <?php
                $counter 
    0;
            }
    ?>
                        <td>
                            <a href="?merk=<?php echo $_GET['merk']; ?>&amp;cat=<?php echo $_GET['cat']; ?>&amp;band=<?php echo $tyre->uitvoeringid?>" title="TYFOON <?php echo $tyre->uitvoeringoms?>" class="link-class" onclick="javascript:saveScrollPositions();">
                            <h2><?php echo $tyre->uitvoeringoms?></h2>
                                <img src="http://www.website.net/banden/<?php if(isset($tyre->uitvoeringfoto) && $tyre->uitvoeringfoto != ""){ echo str_replace(".jpg""-k.png"urlencode ($tyre->uitvoeringfoto)); } else { echo "empty-k.png"; } ?>" height="120" width="77" alt="<?php echo $tyre->uitvoeringoms?>" class="band"/>
                            </a>
                        </td>
    <?php
            $start 
    1;
            
    $counter++;
        }
    ?>
                    </tr>
                </table>
    </div>
    <div class="bandinfo-img">
    <table border="1" class="banden-titel">
    <tr>

    <img src="afbeeldingen/zomerband.jpg" height="145" alt="Tyfoon Zomerband>"/>

    </tr>
    </table>
    </div>
            <div class="bandinfo">
    <?php
        
    if(isset($_GET['band']) && is_numeric($_GET['band']))
        {
            
    $seltyre $banden->getTyres($_GET['cat'], $_GET['merk'], $_GET['band']);
            if(isset(
    $seltyre[0])){ $seltyre $seltyre[0]; }
            else { 
    $seltyre $tyres[0]; }
        }
        else
        {
            
    $seltyre $tyres[0];
        }
    ?>
                <div class="bandinfocontainer">
                <table border="1" class="banden-titel-tekst">
                <tr>
                    <th>
                    Over de: TYFOON <?php echo $seltyre->uitvoeringoms?>
                    </th>
                </tr>
                <tr>
                <td>
    <?php
                    $teksten 
    $banden->getTeksten("01"$seltyre->merkcode."-".$seltyre->uitvoeringisb);
                    if(isset(
    $teksten[0]))
                    {
                        echo 
    $teksten[0]->tekstbes;
                    }
    ?>
                </td>
                </tr>
                </table>
                <table border="1" class="banden-titel-tekst">
                <tr>
                    <th>
                    Maten: TYFOON <?php echo $seltyre->uitvoeringoms?>
                    </th>
                </tr>
                </table>
                <table border="1" class="bandinfoheader">
                        <tr>
                            <th class="extra">Band maat</th>
                            <th class="extra">XL</th>
                            <th class="extra">LI</th>
                            <th class="extra">SI</th>
                            <th><img src="afbeeldingen/labels/brandstof.png" width="30" height="30" alt="<?php echo isset($fuel)? $fuelfalse?>"/></th>
                            <th><img src="afbeeldingen/labels/grip.png" width="30" height="30" alt="<?php echo isset($grip)? $gripfalse?>"/></th>
                            <th><img src="afbeeldingen/labels/geluid.png" width="30" height="30" alt="<?php echo isset($sound)? $soundfalse?>"/></th>
                            <th><img src="afbeeldingen/labels/geluid_db.png" width="30" height="30" alt="<?php echo isset($sound2)? $sound2false?>"/></th>
                        </tr>
                    </table>
                    <div id="maten-wrapper">
                <table border="1" class="banden-titel">
                <?php
        $maten 
    $banden->getBandMaten($_GET['merk'], $seltyre->uitvoeringisb);
        foreach(
    $maten as $maat)
        {
    ?>
                            <tr>
                                <td><?php 
        
    echo $maat->artikelmaat;
        if(!empty(
    $maat->artikelhbv) || $maat->artikelhbv != "")
        {
            echo 
    " / ".$maat->artikelhbv;
        }
        if(!empty(
    $maat->artikeldiameter) || $maat->artikeldiameter != "")
        {
            echo 
    " R".$maat->artikeldiameter;
        }
    ?></td>
                                <td class="si"><?php echo preg_replace("/[^A-Z]/"''$maat->artikel_xl); ?></td>
                                <td class="li"><?php echo preg_replace("/[^0-9]/"''$maat->artikeldraagvermogen); ?></td>
                                <td class="si"><?php echo preg_replace("/[^A-Z]/"''$maat->artikeldraagvermogen); ?></td>
                                <td class="eulabel"><?php echo $maat->artikelbrandstof?></td>
                                <td class="eulabel"><?php echo $maat->artikelgrip?></td>
                                <td class="eulabel"><?php echo (($maat->artikelgeluid == 0) ? "" $maat->artikelgeluid); ?></td>
                                <td class="eulabel"><?php echo (($maat->artikelgeluid2 == 0) ? "" $maat->artikelgeluid2); ?></td>
                            </tr>
    <?php
        
    }
    ?>

                </table>
                </div>
                </div>
            </div>
                        <div class="bandinfoimage">
                    <a href="#" title="TYFOON <?php echo $tyre->uitvoeringoms?>" onclick="fx.changeImage('<?php if(isset($seltyre->uitvoeringfoto) && $seltyre->uitvoeringfoto != ""){ echo str_replace(".jpg"""$seltyre->uitvoeringfoto); } else { echo "empty"; } ?>', this); return false;">
                        <img src="afbeeldingen/vergroot.png" height="21" width="22" alt="zoom" class="zoom"/>
                        <img src="http://www.website.net/preview/<?php  if(isset($seltyre->uitvoeringfoto) && $seltyre->uitvoeringfoto != ""){ echo str_replace(".jpg"".jpg"urlencode ($seltyre->uitvoeringfoto)); } else { echo "empty.png"; } ?>" height="325" width="237" alt="<?php echo $seltyre->uitvoeringoms?>" class="band"/>
                    </a>
                </div>-->
    <?php
        
    }
        else
        {
    ?>
            <table border="1" class="bandenmerken">
                <tr>
    <?php
            
    if(!isset($_GET['type']))
            {
                
    $_GET['type'] = "IMPORT";
            }
            
    $merken $banden->getMerkByCat($_GET['type']);
            
    $counter 0;
            foreach(
    $merken as $merk)
            {
                
    $control $banden->controlTyreCat($merk->merkcode);
                if(isset(
    $control[0]) && !empty($control[0]->uitvoeringid))
                {
                    if(
    $counter == 5)
                    {
                        echo 
    "\t\t\t</tr>
    \t\t\t<tr>\n"
    ;
                        
    $counter 0;
                    }
                    echo 
    "\t\t\t\t<td>
    \t\t\t\t\t<img src=\"http://www.website.net/logos/"
    .str_replace(".png""_125.png"$merk->merklogo)."\" width=\"125\" height=\"53\" alt=\"".$merk->merkoms."\" class=\"logo\"/><br/>
    \t\t\t\t\t<div class=\"types\">\n"
    ;
                    foreach(
    $seasons as $seasonkey => $season)
                    {
                        
    $control $banden->controlTyreCat($merk->merkcode$seasonkey);
                        if(isset(
    $control[0]) && !empty($control[0]->uitvoeringid))
                        {
    ?>
                            <a href="?merk=<?php echo $merk->merkcode?>&amp;cat=<?php echo $seasonkey?>">> <?php echo $season?></a><br/>
    <?php
                        
    }
                    }
                    echo 
    "\t\t\t\t\t</div>
    \t\t\t\t</td>\n"
    ;
                    
    $counter++;
                }
            }
    ?>
                </tr>
            </table>
    <?php
        
    }
    ?>

    <?php   
    the_content
    (); 
    ?>

                        <?php wp_link_pages(array('before' => 'Pages: ''next_or_number' => 'number')); ?>

                    </div>

                </article>

                <?php if(!$data['check_disablecomments']) { ?>
                    <?php comments_template(); ?>
                <?php ?>

                <?php endwhile; endif; ?>
            </div> <!-- end content -->

        </div> <!-- end page-wrap -->

    <?php get_footer(); ?>
    I have a page in WordPress called "Zomerbanden" and I have custom permalinks (/%category%/%postname%/).

    Now I have two problems:

    When I click on the button "Zomerbanden" my url looks like this: www.website.nl/zomerbanden/

    But the script only shows results when the url is like this: www.website.nl/zomerbanden/?merk=TY&cat=ZO

    How can I change the href of that menu button to above url? (www.website.nl/zomerbanden/?merk=TY&cat=ZO)

    My second question is like this:

    As you can see my URL's are very ugly:

    www.website.nl/zomerbanden/?merk=TY&cat=ZO&band=1875

    I want my URL's to look like this:

    www.website.nl/zomerbanden/toayan/zomer/connected

    Can somebody help me out with this?

    Any help would be welcome

    Thanks in advance

    Kind Regards
    Last edited by Mittineague; Aug 28, 2013 at 11:01. Reason: delinking example URLs

  2. #2
    SitePoint Member GaWebDev's Avatar
    Join Date
    Aug 2013
    Location
    Milan, GA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just curious why would you find it necessary to implement mod_rewrite rules in your template? WP already has very flexible url rewrites built into it. If the wp codex itself doesn't support what your looking to achieve I always suggest utilizing mod_rewrite in the htaccess if it's enabled on your server.

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Joepiooo View Post
    When I click on the button "Zomerbanden" my url looks like this: www.website.nl/zomerbanden/

    But the script only shows results when the url is like this: www.website.nl/zomerbanden/?merk=TY&cat=ZO
    You can easily solve that by replacing
    PHP Code:
    $tyres $banden->getTyres($_GET['cat'], $_GET['merk']); 
    with
    PHP Code:
    $tyres $banden->getTyres(isset($_GET['cat']) ? $_GET['cat'] : 'ZO', isset($_GET['merk']) ? $_GET['merk'] : 'TY'); 
    I have no experience with wordpress whatsoever, so I can't help with your other questions.

    Also, you should look at your code again. The lines below:
    PHP Code:
    if(isset($zomer)){$zomer;} 
    if(isset(
    $winter)){$winter;} 
    if(isset(
    $allseason)){$allseason;} 
    if(isset(
    $overig)){$overig;} 
    isset(
    $seasons['ZO']); 
    isset(
    $seasons['WI']); 
    isset(
    $seasons['AS']); 
    isset(
    $seasons['OV']); 
    have no effect whatsoever. You can just remove them without losing any functionality.
    No offence, but it's probably a good idea for you to get a php book to grasp the basics.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •