searchRows & _link

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 6, 2017   (RSS)

By petrogus - August 13, 2017

Hi All,

I create a search page with the results,

                  <?php foreach ($searchRows as $record): ?>
                     <a href="<?php echo $record['_link'] ?>"><strong><?php echo $record['_title'] ?></strong></a><br/>
                     <?php if ($record['_summary']): ?>
                       <?php echo $record['_summary'] ?><br/>
                      <?php else: ?>
                        No description available for page.<br/>
                      <?php endif ?>
                     <a href="<?php echo $record['_link'] ?>" style="color: #999;" ><?php echo $record['_link'] ?></a><br/><br/>
                  <?php endforeach ?>

and the link of the results look like as /news.php?6

but I would like to appear as /news.php?article=6

Could you help ! thank you in advance

P.

PetroGus

By petrogus - August 27, 2017 - edited: August 27, 2017

Hi David,

it works but the problem is that I have different results on search page.

For example <?php echo $record['_link'] ?> show me links like products.php?7 or news.php?2 or article.php?4

I need to create links like products.php?article=7 or news.php?article=2 or article.php?article=4.
Different php page for each results.

thank you for your help

PetroGus

By Dave - September 6, 2017

Hi petrogus, 

I wanted to check if you got this resolved yet?  If not, let me know how you want to decide if the link is to product.php, news.php, etc.

Perhaps you have a field such as 'type' that lists the type of article then you could show the links like this: 

<?php
  $customLink = $record['_link']; // use default if no other option available
  if ($record['type'] == 'article') { $customLink = "/article.php?article=" . $record['num']; }
  if ($record['type'] == 'news')    { $customLink = "/news.php?article=" . $record['num']; }
?>

<a href="<?php echo $customLink; ?>"><strong><?php echo $record['_title'] ?></strong></a><br/>

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com