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.
Related
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']; ?>
For some time I have struggled with what I think should be a simple display of a joined result. My code is as follows.
<h1>start test</h1>
<?php
ee()->db->from('store_orders as so');
ee()->db->join('store_order_items as si', 'so.id = si.order_id', 'inner');
$query = ee()->db->get();
echo '<h1>This is a list of all the channel titles999</h1>';
?>
<ul>
<?php
// print_r($query->result());
foreach($query->result() as $row)
{
echo '<li>' . $row->id . ' - ' . $row->order_id . ' - ' . date('m/d/Y:G:i:s', strtotime($row->order_date)) . '</li>';
}
?>
</ul>
In the foreach loop I want to display the results of the join to make sure that the order id is equal across the 2 tables.....it is not.
I've tried inner, outer, left and right on the join, each giving different results but never what I think should be the correct result...both fields should be the same.
Any help or insight would be appreciated.
BTY, I model my query in MS Access to get my basic syntax.
Thanks
Anthony Jaxon, Los Angeles, CA USA
Because you do a SELECT * and both table have a field called "id", MySQL doesn't know which one you want.
You need to set an aliase to your fields
ee()->db->select('so.id, si.order_id, so.order_date');
ee()->db->join('store_order_items si', 'so.id = si.order_id');
$query = ee()->db->get('store_orders so');
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.
I am creating an order cart.
On the page that displays the cart, it checks if a value stored in the session $order corresponds with an id of a row in a mysql table. If this match exists, then the corresponding row is returned.
Within this process, I am trying to retrieve the quantity value stored in the session $quantity that corresponds to the id of the row in the table.
Each value in $order and $quantityis assigned a name, which is the id of the item they were added from.
This is the code that adds the order to the cart:
if (isset($_POST['action']) and $_POST['action'] == 'Order')
{
// Add item to the end of the $_SESSION['order'] array
$_SESSION['order'][$_POST['id']] = $_POST['id'];
$_SESSION['quantity'][$_POST['id']] = $_POST['quantity'];
header('Location: .');
exit();
}
This is the code on the cart page:
foreach ($order as $item)
foreach ($quantity as $amount)
{
mysql_data_seek( $productsSql, 0); //<- this line, to reset the pointer for every EACH.
while($row = mysql_fetch_assoc($productsSql))
{
$itId = $row['id'];
$itDesc = $row['desc'];
$itPrice1 = $row['price1'];
if ($item == $itId)
{
$pageContent .= '
<tr>
<td>'.$itDesc.'</td>
<td>'.if ($item[''.$itId.''] == $amount[''.$itId.'']) {echo $amount}.'</td>
<td>R'.number_format($itPrice1*$amount, 2).'</td>
</tr>
';
}
}
}
This row is producing a syntax error:
<td>'.if ($item[''.$itId.''] == $amount[''.$itId.'']) {echo $amount}.'</td>
What is the problem here for starters?
Secondly, how would I need to do to accomplish the task that I am facing?
Any input on this would be greatly appreciated!
Could you try this?
<td>'.($item[$itId] == $amount[$itId] ? $amount : '').'</td>
This is a ternary operator, look at http://en.wikipedia.org/wiki/Ternary_operation
You can't simply add conditional statements like that while you're building a string.
You can do this, however
<td>' . ($item[$itId] == $amount[$itId]) ? $amount : null . '</td>
but you should use a more legible method.
Another issue you may get is if $amount is an array, you won't be able to print it as a string. If, however, $amount is an object with ArrayAccess interface, you can print it with the __toString() method; but that's another story.
The code for creating the cart page has several issues.
You walk over items and over quantities, which will probably give you duplicate outputs.
$item is a plain string, so I wonder what $item[$itId] is supposed to do?
You walk over your complete result set several times which actually is not necessary. I really hope that "$productSql" isn't a "select * from product", otherwhise this might get REAL slow in production mode.
I suggest creating a good SQL for getting the data and using this as a basis for filling the page:
// note this has SQL-injection issues, so you really need to make sure that $order contains no crap
$productsSql = mysql_query("select * from product where id in (".join($order, ',').")");
// you now have a result set with all products from your order.
while($row = mysql_fetch_assoc($productsSql))
{
$itId = $row['id'];
$itDesc = $row['desc'];
$itPrice1 = $row['price1'];
// session contains the quantity array mapping ID -> Quantity, so grab it from there
$itQuantity = $quantity[$itId];
// finally calculate the price
$itPrice = number_format($itPrice1*$itQuantity, 2);
// now you have all data for your template and can just insert it.
// if you use double quotes you can put the $xyz into the string directly
$pageContent .= "
<tr>
<td>$itDesc</td>
<td>$itQuanty</td>
<td>R $itPrice</td>
</tr>
";
}