I've add module "categories" to homepage, and now I see categories list with numer of products on homepage but can't see category thumbs.
in file: /public_html/catalog/view/theme/MY-THEME/template/module/category.tpl I found around line 10:
<?php echo $category['name']; ?>
and I think sommewhere there I also should add something like: category['thumb'] to display image before category name but do I have to add something in controller files, I soppouse yes but need help here.
I thing i should define $category['thumb'] in controller but how to do this?
You're correct in saying that you need to edit the controller file for this module, you need to add the model that gets the image for that category as well as get the image for any child categories. So there are two edits you need to make, first to the controller file
Open the catalog/controller/module/category.php & find this line:
$this->load->model('catalog/product');
Now you need to add the model so that you can get the image data from the DB, add this line below it:
$this->load->model('tool/image');
Now find this line, it will be in the foreach loop:
$children = $this->model_catalog_category>getCategories($category['category_id']);
Add the following above the line:
$category_info = $this->model_catalog_category>getCategory($category['category_id']);
if ($category_info['image']) {
$image = $category_info['image'];
} else {
$image = '';
}
You also need to do this for the child categories, find this line in the next foreach loop:
$product_total = $this->model_catalog_product->getTotalProducts($data);
Add this directly below it:
$child_info = $this->model_catalog_category>getCategory($child['category_id']);
if ($child_info['image']) {
$child_image = $child_info['image'];
} else {
$child_image = '';
}
At the moment we now have two variables that contain the image paths: $image and $child_image, these need to be passed to the template file, you can do so by editing the two arrays that are created. We'll do the child array first as that is almost directly below the last edit you made. Find this line in the children_data array:
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
Add a comma to the end of the line and paste this line directly below it:
'image' => $child_image
Now we add the image to the $category array, find this line and add a comma to the end as with the last step:
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
The next step is obvious now, add the following line directly below it:
'image' => $image
Now you should note that the template file can access a new variable $image when in the foreach loops. I'll leave the rest to you as you'd know how and where you'd like to display the image. The code below will generate an image if it's used in the foreach loop of either the Category:
<img src="<?php echo $category['image']; ?>
Or this can be used for a child category:
<img src="<?php echo $child['image']; ?>
Related
I am using openTBS to update a slide deck and need to also update/replace template content in the Notes section. Is there a command that supports that?
There is not native command for doing this but there is work around.
In a PPTX, comments are stored into sub XLM files such as ppt/comments/comment2.xml.
Each slide may have its own Comment sub-file.
I’s a bit complicated to find which Comment file is corresponding to what slide.
But you can find all Comment files in the PPTX using a code like this :
$all = $TBS->Plugin(OPENTBS_GET_FILES);
$comments = array();
foreach ($all as $file) {
if (substr($file, 0, 13) == 'ppt/comments/') {
$comments[] = $file;
}
}
Then you can open each sub-file and merge data as an XML file.
foreach ($comments as $file) {
$TBS->PlugIn(OPENTBS_SELECT_FILE, $file);
$TBS->MergeFields(...);
}
I have some $data that i am transfering to view, ok that is easy
But i want this
$data['promenjive']=array
(
'1' => prva,
'2' => 'druga',
'3' => 'treca',
);
And
$this->load->view("view_home", $data);
My question is how to echo a single value from $data['promenjive']
To make something like this
1
I dont want to foreach entire array just one element?
In your example prva would echoed from within your view template with:
<?php echo $promenjive[1];?>
To echo 1 from your example you would have to do:
<?php echo array_search('druga',$promenjive);?>
I've been looking everywhere but haven't found the answer to the question: How can I use my own thumbnail per feed in a multifeed page? If I've overlooked the answer it would be due to the wrong search keys for which i apologize in advance.
I've got the following code so far (which is not much):
<?php
include_once('autoloader.php');
include_once('idn/idna_convert.class.php');
date_default_timezone_set('Europe/Amsterdam');
setlocale(LC_TIME, 'nld_nld');
$feed = new SimplePie();
$urls = (array(
'http://myfeedurla.com' => 'descriptiona',
'http://myfeedurlb.com' => 'descriptionb',
'http://myfeedurlc.com' => 'descriptionc'
));
$feed->set_feed_url(array_keys($urls)); // this should get parse only the URLS
$feed->set_cache_location('cache/');
$feed->init();
$feed->handle_content_type();
?>
// As from here I'm using the standard simplepie code to show multiple feeds and order them by day
<?php
// Set up some variables we'll use.
$stored_date = '';
$list_open = false;
// Go through all of the items in the feed
foreach ($feed->get_items() as $item)
{
// What is the date of the current feed item?
$item_date = $item->get_date('M jS');
// Is the item's date the same as what is already stored?
// - Yes? Don't display it again because we've already displayed it for this date.
// - No? So we have something different. We should display that.
if ($stored_date != $item_date)
{
// If there was already a list open from a previous iteration of the loop, close it
if ($list_open)
{
echo '</ol>' . "\r\n";
}
// Since they're different, let's replace the old stored date with the new one
$stored_date = $item_date;
// Display it on the page, and start a new list
echo '<h1>' . $item->get_local_date('%A %d %B %Y') . '</h1><hr>' . "\r\n";
echo '<ol>' . "\r\n";
// Let the next loop know that a list is already open, so that it will know to close it.
$list_open = true;
}
// Display the feed item however you want...
echo '<li>' . $item->get_local_date('%H:%M') . ' | <h4>' . $item->get_title() . '</h4></li>' . "\r\n";
}
?>
Somewhere in the HTML I want to add the 'img scr=" . . "' etc. And there it should only refer to an image by the name 'descriptiona'.png respectively 'descriptionb'.png etc, per feed. Is this possible? And if yes, how?
If I should be more clear, pls don't hesitate to ask. Thanks in advance for the help!
Best regards,
Ok, so far I have one solution :) I use the title of the respective feeds in the img filename. I've added the following code:
<img src="images/' . $item->get_feed()->get_title() . '.png" width="12" height="12" />
Now I only hope that feeds won't use / or something in their titles... If someone has a better way of doing this, eg. by being able to add a personal title per feed, that would be very welcome.
its a silly question but I'm really bad in escaping quotes :/.
I'm using the table class to generate a table of products, and in that table each row has an image to be displayed for that product. The images are stored using their product_id as a name with an appended "_x" because there's more than one image per product, so an example of an image name is 193_1.
This is how I'm generating my rows for the table:
$table_row = array();
foreach ($r->result() as $p)
{
$table_row = NULL;
$table_row[] = "<img src='http://localhost/CI/photos/$p->product_id\"1\".jpg' height='150' width='150'/>";
$table_row[] = $p->product_id;
$table_row[] = $p->title;
$table_row[] = $p->description;
$table_row[] = $p->price;
$table_row[] = $p->stock;
$this->table->add_row($table_row);
}
But the image won't show, even when I've escaped the '1'. I only want to display the first image as that is the main one, so that's why I've hard-coded the number. Could someone please help? I've tried multiple ways i.e.
"<img src='http://localhost/CI/photos/$p->product_id '1' .jpg' height='150' width='150'/>"
"<img src='http://localhost/CodeIgniter/photos/<?php echo $p->product_id; ?>1.jpg' height='150' width='150'/>";
But the image still doesn't show. The table is being generated in my Controller which is a PHP file so I don't really think I need to use php tags
"<img src='http://localhost/CodeIgniter/images/" . $product->product_id . "_1.jpg' height='100' width='100'/>";
I am using the NextGen gallery WordPress plugin for a site. In my gallery.php template I want to retrieve the number of images for each gallery displayed in the loop. I cannot figure out a way to get the data and print it under the thumbnail of each gallery that's called in gallery.php
Here is where I want to insert the gallery image count and print it:
<a rel="prettyPhoto" href="<?php echo $image->imageURL ?>"
<?php $image->thumbcode ?>><span>view</span></a> <?php echo $total_images; ?> pictures
Anybody have any tips?
Thanks,
Ian
I used this little hack to get my gallery id from the shortcode I pasted inside my post ([nggallery=1])
<?php
$id = get_the_ID();//Get the id of the specific post (inside the loop)
$string = get_the_content();//You get the whole post content where in the end of it lies your shortcode (for example [nggallery=1])
if(preg_match_all('/=(.*?)\]/s',$string,$match)) {
$finalstring=$match[1][0];
}// get the id only (gets all chars after '=' and before ']')
global $wpdb;
$total_attachments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid=$finalstring" ); // Voila!
?>
Hope my solution can work for you.
This is the code you need to count the images:
$global $wpdb;
$images = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures") );
$galleries = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggallery") );
$albums = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggalbum") );
The answer is you can't.
You can count the keys in the $images variable but it will return the wrong number.
You can retrieve the total number of all the images, or all the galleries which is useless.
You can even use a counter as you cycle through the array to try to count how many images are in your gallery, but you'll still get the wrong number.
You can try to use the global variables tthere by default: images->total, which are empty and undefined and don't even exist in the $images or $current object.
The code displays a ("Picture 3 of 7)" type display. If you use it in the imagebrowser.php template, it works. If you paste this exact same code in the gallery-carousel.php template. It will not work. Now you might think switching to $current->total would work, since it inexplicably does for the rest of the variables when using gallery_carousel, but no, it does not. The answer is you have to pull the info from the database directly.
<?php _e('Picture', 'nggallery') ?> <?php echo $image->number ?> <?php _e('of', 'nggallery')?> <?php echo $image->total ?>
It is a sinister, sinister plugin.
If you can't count the images on a gallery, you can count the tags on html block.
On my theme, I get the gallery ID from an custom field and echo the gallery inside the template. So, it's something like that:
<?php
$myGalleryId = 1; // example
$displayImages = 0; // the number of images you want to display from gallery. 0 = all images
$newnggShortcodes = new NextGEN_Shortcodes;
$htmlGallery = str_get_html($newnggShortcodes->show_gallery( array("id"=>$myGalleryId,"images"=>$displayImages,"template"=>"popular") ));
$countImg = count($htmlGallery->find('img')); // number of total <img> tags inside the gallery
$str = $htmlGallery;
?>
<!-- now the html -->
<div id="myGallery">
<?php echo $str; ?>
</div>
<span>Total images: <?php echo $countImg; ?></span>
Hope it helps.