Jump to content

Problem Retrieving Array


edawg

Recommended Posts

I use Popshops Datafeed API and cant figure out an issue im having with an array. I'm trying to retrieve a category name from an array for the current page.

 

Here is the array code which is in the index.php file.

 

$categories = array();
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );
  $categories[] = array( 'name' => 'page name', 
                         'search_options' => array( 'keywords' => 'page keyword' ) );

 

This is how the script calls the current page keyword.

<?php echo ucwords($_REQUEST[$popshops->nameSpace.'keywords']) ?> 

 

The code above works fine, so I thought all I had to do was change the 'keywords' to 'name' to get what I was looking for. But that does not seem to work?

<?php echo ucwords($_REQUEST[$popshops->nameSpace.'name']) ?> 

:shrug:

 

I've tried as much as my limited php knowledge can take me, so now I need some advice.

 

Here is the function in the popshops.php file they use to pull the page name out for the links in the navigation, but I just want to know how to retrieve just the category name for the current page, nothing else.

 

function customCategoryLink($category) {
    $url = $this->baseURL($this->params);
    
    if (isset($category['search_options']) && sizeOf($category['search_options']) > 0) {
      foreach($category['search_options'] as $key => $value) {
        $url = $this->addParameter($url,$key,$value);
      }      
    } else {
      $url = $this->addParameter($url,'keywords',$category['name']);
    }
    $url = str_replace('?&','?',$url);
    return '<a href="'.$url.'">'.$category['name'].'</a>';
  }

 

Thanks in advanced!

 

Link to comment
Share on other sites

Thanks!

 

BaseURL function.

function baseURL($paramNamesToStrip) {
    $url = $this->requestURI();        
    foreach ($_REQUEST as $key => $value) {
      foreach ($paramNamesToStrip as $paramName) {
        $url = $this->stripParameter($url,$paramName,$key,$value);
      }      
    }        
    return $url;
  }  

 

AddParameter Function.

function addParameter($url,$paramName,$paramValue) {
    if (strlen($paramValue) > 0) {
      $delimiter = (strpos($url,'?') > -1) ? '&' : '?';    
      $url = $url.$delimiter.$this->nameSpace.$paramName.'='.urlencode($paramValue);
    }
    return $url;
  }

 

 

Link to comment
Share on other sites

Dont know if this will help any, but here is the function that displays the categories.

 

 

function renderCustomCategories(){
    $out = '';
    if (sizeOf($this->categories) > 0) {
      $out .= '<h3>Popular categories</h3>';
      $out .= '<ul>';
      foreach ($this->categories as $category) {
        $out .= '<li>'.$this->customCategoryLink($category).'</li>';
      }
  $out .= '</ul>';      
    }
    return $out;
  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.