SQL statement category list

Your code modifications and patches you want to share with others.
Locked
mschram
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jul 10, 2009 8:41 pm

SQL statement category list

Post by mschram » Sat Oct 10, 2009 9:52 am

Hi,

I'm looking for the place where I can alter the SQL select statement that is used for the list of articles within a category.

Thank you very much!

Kind regards,
Martijn Schram

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: SQL statement category list

Post by ooffick » Sat Oct 10, 2009 7:25 pm

You cannot do that without changing the core files. What are you trying to do? Maybe the change can be done with a plugin as well.

Olaf
Olaf Offick - Global Moderator
learnskills.org

mschram
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jul 10, 2009 8:41 pm

Re: SQL statement category list

Post by mschram » Sat Oct 10, 2009 8:19 pm

I know I have to change the core files (done it before :))
I have made a custom plugin that inserts 5 articles when you add a new article.
In this way each article has 5 subarticles (see http://www.watkoopik.nl for an example, pages are in Dutch though....). In the jos_content table is a custom field that I use to identify the type of subarticle (1 is the main article).

The problem is that if you click on a category you will see all articles times 5.
So I want to include a WHERE statement like WHERE cust_type=1

Regards,
Martijn

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: SQL statement category list

Post by ooffick » Sat Oct 10, 2009 8:52 pm

You could try to hide it by using a template overwrite of the category list view.
  1. create a folder in your template folder called "html" (if it doesn't exists)
  2. create a folder in that html folder called "com_content" (if it doesn't exists)
  3. create a folder in that com_content folder called "category" (if it doesn't exists)
  4. copy the file .../components/com_content/views/category/tmpl/default_item.php in this .../templates/[your-template]/html/com_content/category/ folder
  5. open that file
  6. find the following lines:

    Code: Select all

    <?php foreach ($this->items as $item) : ?>
  7. and replace it with the following:

    Code: Select all

    <?php foreach ($this->items as $item) : 
    if($item->your_parameter) continue;
    ?>
    
    (you will need to set your_parameter to your sql_coloumn or to a parameter params->get('your-parameter') to get your parameter)
  8. save the file
Olaf
Olaf Offick - Global Moderator
learnskills.org

mschram
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jul 10, 2009 8:41 pm

Re: SQL statement category list

Post by mschram » Sun Oct 11, 2009 7:57 am

Olaf,

Thank you for your solution.
I've added this code to the default_items.php file:

Code: Select all

<?php foreach ($this->items as $item) : 
if($item->cust_type==1) continue;
?>
But it does not seem to work. I think the $item->cust_type statement does not retrieve the correct value. I have checked it with other code (if(1==1) continue) and that hided all the articles. How can I link the $item->cust_type statement to the correct value?

BTW: Why do I have to put the file in the template directory? Doesn't that get me in trouble with new releases of Joomla?

Thanks
Martijn

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: SQL statement category list

Post by ooffick » Sun Oct 11, 2009 9:54 am

mschram wrote:BTW: Why do I have to put the file in the template directory? Doesn't that get me in trouble with new releases of Joomla?
well, if you put it into the template you can still upgrade to a new version, if you make a change in any of the core files you will need to make the changes again, after you upgraded to the new version.

Olaf
Olaf Offick - Global Moderator
learnskills.org

mschram
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jul 10, 2009 8:41 pm

Re: SQL statement category list

Post by mschram » Sat Oct 17, 2009 12:04 pm

I have done the following:

1) Added field cust_type to jos_content (type = tinyint)
2) Added

Code: Select all

var $cust_type = null; 
to libraries\joomla\database\table\content.php
3) Added

Code: Select all

$form->set('cust_type', $row->cust_type); 
to administrator/components/com_content/controller.php
4) Added

Code: Select all

		<param name="cust_type" type="list" default="" label="Article type" description="Article type">
			<option value="1">Beschrijving</option>
			<option value="2">Specificaties</option>
			<option value="3">Afbeeldingen</option>
			<option value="4">Handleidingen</option>
			<option value="5">Recencies</option>
		</param>
to administrator/components/com_content/models/article.xml

This all seems to work: I get an extra combobox in the administrator part of the articles.

But once I try to use the field in the front-end (through item->cust_type) I get no data.

For example:

Code: Select all

	<td><?php echo $item->cust_type; ?>
		<a href="<?php echo $item->link; ?>">
			<?php echo $this->escape($item->title); ?></a>
			<?php $this->item = $item; echo JHTML::_('icon.edit', $item, $this->params, $this->access) ?>
	</td>
in components\com_content\views\category\tmpl\default_items.php

I replaced $item->cust_type with $item->title, and then I did see the title.

The statement $item->cust_type does not seem to work.
What am I missing here????

Thanks Martijn

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: SQL statement category list

Post by ooffick » Sun Oct 18, 2009 9:08 pm

Mod Note: Moved to Core Hacks and Patches

Olaf
Olaf Offick - Global Moderator
learnskills.org

mschram
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jul 10, 2009 8:41 pm

Re: SQL statement category list

Post by mschram » Thu Oct 22, 2009 9:29 pm

I found a workaround for the category list, but I still want to use the $item->cust_type statement.
Can someone help me?
Big Thanks!
Martijn


Locked

Return to “Core Hacks and Patches”