Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Categories and news not showing up

 
Reply to topic    Forum Index » Bugs and errors View previous topic
View next topic
Categories and news not showing up
Author Message
niaccurshi



Joined: 03 Feb 2008
Posts: 12

Post Categories and news not showing up Reply with quote
OK, so after posting my problem in the help section I've now found out where the issue lies but am unsure of how to solve it.

Basically, both my issues stem from the following...

Let's I have a category, it's number is "2". With the current version of Cutenews.ru if I set it to display only news with the category number 2 in it's multiple categories it will include include all news with the category ID "2", but not if it's also got a category with "2" in it's number.

For example, let's say my page is set to display all news from category with ID "12". I have 3 news items, the first has only the category 12 assigned to it, the second has category 12, 13 and 101 assigned to it, the third has category 1, 4, 12 and 112 assigned to it.

One and two display fine, but the third will not because the code is currently saying that it can only display categories with the ID "12" but not if the news story is assigned a category with "12" somewhere inside of it, such as 112, 212, 312, 120, 121, etc, etc...

How easy is it to change the logic so that it isn't "Category from this ID and NOT these ID's" but rather "Category from this ID, and NOT these ID's unless the Category from the first ID is present"?
Mon Feb 04, 2008 2:25 pm View user's profile Send private message
Guest








Please login to hide the ads.

niaccurshi



Joined: 03 Feb 2008
Posts: 12

Post Reply with quote
Think I may have the solution after all...

Change:

Code:
if ($allow_categories[0] != ''){
      foreach ($allow_categories as $k => $v){
      
         for ($i = 0; $i < 10; $i++){
            if (!in_array($v.$i, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$v.$i.'%';
            }

            if (!in_array($i.$v, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$i.$v.'%';
            }
         }
      }
      $where[] = 'and';
      foreach($allow_categories as $single_cat){
         $where[] = 'category =~ %'.$single_cat.'%';
         $where[] = 'or';
      }
      
      unset($where[count($where)-1]);
   }


To:

Code:
if ($allow_categories[0] != ''){
      foreach ($allow_categories as $k => $v){
      
         /*for ($i = 0; $i < 10; $i++){
            if (!in_array($v.$i, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$v.$i.'%';
            }

            if (!in_array($i.$v, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$i.$v.'%';
            }
         }*/
      }
      $where[] = 'and';
      foreach($allow_categories as $single_cat){
         $where[] = 'category =~ %,'.$single_cat.',%';
         $where[] = 'or';
      }
      
      unset($where[count($where)-1]);
   }


Basically it now looks for a specific category (or categories, though I haven't tested multiple categories being selected in the main page) while allowing the news items it finds to have multiple categories. Can anyone see any problems with this?
Mon Feb 04, 2008 2:46 pm View user's profile Send private message
niaccurshi



Joined: 03 Feb 2008
Posts: 12

Post Reply with quote
OK, found my own errors, basically you need to have the following:

Code:
foreach($allow_categories as $single_cat){
         $where[] = 'category =~ %,'.$single_cat.',%';
         $where[] = 'or';
         $where[] = 'category =~ '.$single_cat;
         $where[] = 'or';
         $where[] = 'category =~ ^'.$single_cat.',%';
         $where[] = 'or';
         $where[] = 'category =~ %,'.$single_cat;
      }


So essentially it only pulls out news that has the category you specify assigned to it, either as a multiple or as a single, and it also checks for categories on the start or end of the list.
Mon Feb 04, 2008 2:57 pm View user's profile Send private message
niaccurshi



Joined: 03 Feb 2008
Posts: 12

Post Reply with quote
OK, so the above breaks the calendar function, so if you need that then you're better off with...

Code:
if ($allow_categories[0] != ''){
      foreach ($allow_categories as $k => $v){
      
         for ($i = 0; $i < 10; $i++){
            if ($v < 9) {
               for ($j = 0; $j < 2; $j++) {
                  if (!in_array($v.$i, $allow_categories)){
                     $where[] = 'and';
                     $where[] = 'category !~ %'.$j.$v.$i.'%';
                  }

                  if (!in_array($i.$v, $allow_categories)){
                     $where[] = 'and';
                     $where[] = 'category !~ %'.$j.$i.$v.'%';
                  }
               }
            }
   
            if (!in_array($v.$i, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$v.$i.'%';
            }

            if (!in_array($i.$v, $allow_categories)){
               $where[] = 'and';
               $where[] = 'category !~ %'.$i.$v.'%';
            }
         }

      }
      $where[] = 'and';
      foreach($allow_categories as $single_cat){
         $where[] = 'category =~ %,?'.$single_cat.',?%';
         $where[] = 'and';

      }
      unset($where[count($where)-1]);


Though with lots of static news includes it will cause some load times it seems.
Thu Feb 28, 2008 2:47 am View user's profile Send private message
niaccurshi



Joined: 03 Feb 2008
Posts: 12

Post Reply with quote
Alright, so the last code returned my original problem! Finally after looking in to everything this works. It takes only news where the category is defined, and it works with the calendar function. I'd update this if you're ever going to use more than 100 categories, or even just use lots of multiple categories.

Code:
$where[] = 'and';
      foreach($allow_categories as $single_cat){
         $linkOne = '^'.$single_cat.',%';
         $linkTwo = '%,'.$single_cat.',%';
         $linkThree = '%,'.$single_cat.'$';
         $linkFour = '^'.$single_cat.'$';
         $where[] = 'category =~ '.$linkTwo.'|'.$linkOne.'|'.$linkThree.'|'.$linkFour;
         $where[] = 'and';

      }
      unset($where[count($where)-1]);

Tue Mar 04, 2008 7:18 am View user's profile Send private message
D72



Joined: 22 Feb 2007
Posts: 217
Location: NL

Post Reply with quote
Looks like you have a whole conversation and helpdesk with your self here Very Happy
Sat Mar 22, 2008 12:53 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Quote:
Looks like you have a whole conversation and helpdesk with your self here Very Happy


lol that's exactly what I was thinking. I feel bad no one came to help you but I really have no idea what you're working with there

At least you're working hard and figuring it out.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Sat Mar 22, 2008 11:39 pm View user's profile Send private message Visit poster's website AIM Address
D72



Joined: 22 Feb 2007
Posts: 217
Location: NL

Post Reply with quote
[quote="scottdallas"]
Quote:
At least you're working hard and figuring it out.


Same here, i read and tried to understand, but couldnt point my finger on something that could be helpfull.
Sun Mar 23, 2008 1:38 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    Forum Index » Bugs and errors All times are GMT + 1 Hour
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.