Post by kreativ » Tue Oct 11, 2011 8:30 pm

After resolving the original issue I had with the removal of the Refine Search (http://forum.opencart.com/viewtopic.php?f=20&t=41699) I realized, rather than removing them entirely, I'd rather substitute the textual results for some icons/buttons for each subcategory; but the problem I am facing is that even though I can create the icons and subsequent links, ONLY one icon set displays in all the categories and subcategory pages.

I understand before someone kicks off about that I am only changing one file (category.tpl) and whatever I do here, it would cascade down affecting ALL other categories and subcategory pages... :(

The navigation tree is as follows:
Category 1 id 30
  • sub-cat1 id 32
    sub-cat2 id 33
    sub-cat3 id 34
Category 2 id 50
  • sub-cat1 id 51
    sub-cat2 id 52
I am learning PHP so, I know there must be a way to do this but escapes me at the mo'.. ;D I have each category and subcategory's id but I cannot figure out how to make an if statement that can do this...

I have the icons for Category1 and for each sub-categories as a HTML table (easiest way and quicker to do) ; so the concept would be if I click on Category1 it displays the icons for the sub-categories in Category1 but if I chose Category2 it displays the sub-categories icons for Category2.....I hope I am making sense here.
Last edited by kreativ on Wed Oct 12, 2011 3:30 am, edited 1 time in total.

Newbie

Posts

Joined
Fri Sep 02, 2011 4:55 am

Post by kreativ » Wed Oct 12, 2011 3:30 am

I know is not the most elegant solution, but is the only I could come up with at this stage 8) . If someone has a better and sliker solution it would be great to hear.

A word of warning, you must have a basic understanding of HTML and a bit of PHP to attempt this, this code is not a copy paste solution...you have to get your hands dirty to make sure everything works

Lines 19-41 on catalog\view\theme\default\category.tpl to be changed

Code: Select all

<?php if ($categories) { ?>
	<h2><?php echo $text_refine; ?></h2>
	<div class="category-list">
		<?php if (count($categories) <= 5) { ?>
			<ul>
		<?php foreach ($categories as $category) { ?>
			<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
		<?php } ?>
			</ul>
		<?php } else { ?>
		<?php for ($i = 0; $i < count($categories);) { ?>
			<ul>
		<?php $j = $i + ceil(count($categories) / 4); ?>
		<?php for (; $i < $j; $i++) { ?>
		<?php if (isset($categories[$i])) { ?>
			<li><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
		<?php } ?>
		<?php } ?>
			</ul>
		<?php } ?>
		<?php } ?>
	</div>
<?php } ?>

Replace for (notice there are a few lines of comment in the next code explaining how I did it):

Code: Select all

<?php if ($categories) { ?>
		<h2><?php echo $text_refine; ?></h2>
		<div class="category-list">

			<?php 
				$my_variable = $_GET['path'];
			?>
		<!-- NOTE: check the link on the address bar and make note of the
				number next to the path, in this example the address for the MAIN category is:
				"http://localhost/wordpress/opencart/index.php?route=product/category&path=62"
				
				The ELSE IF statement in this example is for a sub-categories of the main sub-category,
				in other words is for a third level navigation
				
				Main Category > level1 sub-cat > level2 sub-cat
				62 > 62_63 > 62_63_68
		-->
			<?php if($my_variable == '62'){ 
				echo '
				<div class="cat_bttn">
				<table id="first_cat">
					<tr>
						<td>
							<a href="URL/index.php?route=product/category&path=62_63">
							<img src="http://URL/image/data/icons/file1.jpg" />
							<br/><span>First Sub-Category ITEM fom CATEGORY 1</span></a>
						</td>
						<td>
							<a href="http://URL/index.php?route=product/category&path=62_64">
							<img src="http://URL/image/data/icons/file2.jpg" />
							<br/><span>Second Sub-Category ITEM fom CATEGORY 1</span></a>
						</td>
						<td>
							<a href="http://URL/index.php?route=product/category&path=62_65">
							<img src="http://URL/image/data/icons/file3.jpg" />
							<br/><span>Third Sub-Category ITEM fom CATEGORY 1</span></a>
						</td>
						<td>
							<a href="http://URL/index.php?route=product/category&path=62_66">
							<img src="http://URL/image/data/icons/file4.jpg" />
							<br/><span>Fourth Sub-Category ITEM fom CATEGORY 1</span></a>
						</td>
						<td>
							<a href="http://URL/index.php?route=product/category&path=62_67">
							<img src="http://URL/image/data/icons/file5.jpg" />
							<br/><span>Fifth Sub-Category ITEM fom CATEGORY 1</span></a>
						</td>
					</tr>
				</table>
				</div>';
				} else if($my_variable == '62_63'){
				echo '
				<div class="cat_bttn">
					<table id="second_cat">
						<tr>
							<td>
								<a href="http://URL/index.php?route=product/category&path=62_63_68">
								<img src="http://URL/image/data/icons/file1.jpg" /><br/>
								<span>First Sub-Category ITEM from sub-category 1</span></a>
							</td>
							<td>
								<a href="http://URL/index.php?route=product/category&path=62_63_69">
								<img src="http://URL/image/data/icons/file2.jpg" /><br />
								<span>Second Sub-Category ITEM from sub-category 1</span></a>
							</td>
							<td>
								<a href="http://URL/index.php?route=product/category&path=62_63_70">
								<img src="http://URL/image/data/icons/file3.jpg" /><br />
								<span>Third Sub-Category ITEM from sub-category 1</span></a>
							</td>
						</tr>
					</table>
				</div>';
				}
			?>			
		</div>
	<?php } ?> 

Newbie

Posts

Joined
Fri Sep 02, 2011 4:55 am
Who is online

Users browsing this forum: No registered users and 100 guests