What is the way to load more than one XML (different sources) and show a mixed content?
My Code is now loading only one XML now
<?php
$mobile = simplexml_load_file('mobile.xml');
$electronics = simplexml_load_file('electronics.xml');
foreach($mobile->product as $product)
{
echo '<div class="col-md-3">'."\n";
echo '<h4 class="img-responsive">'.$product->name.'</h4>'."\n";
echo '<p><img src="'.$product->image->large.'" class="img-responsive" /></p>'."\n";
echo '<p>'.$product->Price.'</p>'."\n";
echo '</div><!--end painting_record-->'."\n";
}
foreach($electronics->product as $product)
{
echo '<div class="col-md-3">'."\n";
echo '<h4 class="img-responsive">'.$product->name.'</h4>'."\n";
echo '<p><img src="'.$product->image->large.'" class="img-responsive" /></p>'."\n";
echo '<p>'.$product->Price.'</p>'."\n";
echo '</div><!--end painting_record-->'."\n";
}
?>
Thanks
Mix them how? It looks like your code would show them all in one list with mobile on the top and electronics at the bottom. I guess you could do something like (paracoding here)...
foreach($mobile->product as $product) { array_push($newList,$product); }
foreach($electronics->product as $product) { array_push($newList,$product); }
Then do a foreach on $newList, but sorting them however you want.
Related
I have following code to get all the reviews. It works but the problem is it's also printing the pending reviews. It should only print the ones that are approved.
$review = Mage::getModel('review/review');
$collection = $review->getProductCollection();
$collection
->addAttributeToSelect('*')
->getSelect()
->limit($limitertest)
->order('RAND()');
$review->appendSummary($collection);
echo '<ul class="testimony_slider">';
foreach($collection as $product) {
echo '<li>';
echo '<div class="testi_left">';
echo '<img src='.Mage::helper('catalog/image')->init($product, 'small_image')->resize(100).'>';
echo '</div>';
echo '<div class="testi_right">';
echo '<p class="testti_summery">"'.$product->getTitle().'"</p>';
echo '<p class="testti_nickname">'.$product->getNickname().'</p>';
echo '</div>';
echo '<div class="clear_both"></div>';
echo '</li>';
}
echo '</ul>';
You may need to refactor your code to get the reviews collection, then filter by the approved status. Something like this:
$reviews = Mage::getModel('review/review')->getResourceCollection();
$reviews->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED);
I'm trying to make an if condition if there's a tag then echo it if not just show the archive title.
$title_before = '<h1 class="archive_header">';
$title_after = '</h1>';
if(is_tag('tag_description')){
echo '<div class="archive_desc">';
echo tag_description();
echo '</div>';
echo '<div class="archive_border"></div>';
} else {
woo_archive_title( $title_before, $title_after );
}
I tried the code above and the tag description is not showing, though I'm not entirely sure if is_tag covers tag_description.
The is_tag function checks if a tag archive page is being displayed.
Is that what you want?
Found my way now, I wanted !empty. So if there is no tag/archive description it only shows the title, then if exist it shows both.
$tag_description = tag_description();
woo_archive_title( $title_before, $title_after );
if(!empty($tag_description)){
echo '<div class="archive_desc">' .$tag_description. '</div>';
echo '<div class="archive_border"></div>';
} else {
//
}
Now I need to do the styling.
In WordPress i'm currently using Yoast's SEO Plugin to display breadcrumbs for my pages and posts, which is working fine when visiting a specific page.
Here is the function i'm using to display the breadcrumbs inside of my WordPress templates:
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>
For example when browsing to Team Members which is a child of About Us I get:
Home > About Us > Team Members
However i'd like to be able to display the same breadcrumbs (for the individual pages and posts) inside the search results loop.
So far what displays when searching for Members is:
Your Search Results:
Team Members
Home > Search > Members
Members Area
Home > Search > Members
But I don't want breadcrumbs for the Search Results page, I want them for the individual pages and posts that are displayed as a result of searching for a keyword.
For example Imagine I searched again for Members I would like displayed the below:
Your Search Results:
Team Members
Home > About Us > Team Members
Members Area
Home > Members Area
I'm not fussed if this is or isn't integrated with the SEO plugin, however thus far it's the best solution I found to display breadcrumbs in WordPress!
Also incase abody requires it, here is my search.php file: http://pastebin.com/0qjb2954
Try this. That's my own working snippet that shows breadcrumbs inside search loop.
/*Begin Loop */
<?php
echo '<div class="b-search_result_list__item_breadcrumbs breadcrumbs">';
$current_type = get_post_type();
if ($current_type == 'page') {
$parents = get_post_ancestors(get_the_ID());
if($parents){
for($i=count($parents)-1;$i>=0;$i--){
echo '<span typeof="v:Breadcrumb">';
echo '<a rel="v:url" property="v:title" title="'.get_the_title($parents[$i]).'" href="'.get_permalink($parents[$i]).'">'.get_the_title($parents[$i]).'</a>';
echo '</span>';
}
}else{
echo '<span typeof="v:Breadcrumb">';
echo '<a rel="v:url" property="v:title" title="'.get_bloginfo('name').'" href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a>';
echo '</span>';
}
echo '<span typeof="v:Breadcrumb">';
echo '<span property="v:title">'.get_the_title().'</span>';
echo '</span>';
}else{
$current_obj = get_post_type_object($current_type);
echo '<span typeof="v:Breadcrumb">';
echo '<a rel="v:url" property="v:title" title="'.get_bloginfo('name').'" href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a>';
echo '</span>';
echo '<span typeof="v:Breadcrumb">';
echo '<a rel="v:url" property="v:title" title="'.$current_obj->labels->name.'" href="'.get_post_type_archive_link( $current_type ).'">'.$current_obj->labels->name.'</a>';
echo '</span>';
$current_taxonomies = get_object_taxonomies($current_type);
if($current_taxonomies){
$current_terms = get_the_terms(get_the_ID(), $current_taxonomies[0]);
if($current_terms){
$current_term = array_shift($current_terms);
echo '<span typeof="v:Breadcrumb">';
echo '<a rel="v:url" property="v:title" title="'.$current_term->name.'" href="'.get_term_link($current_term).'">'.$current_term->name.'</a>';
echo '</span>';
/*
var_dump($current_obj->labels->name); // Archive name
var_dump(get_post_type_archive_link( $current_type )); // Archive link
var_dump($current_term->name); // Term name
var_dump(get_term_link($current_term)); // Term link
var_dump(get_permalink()); // Post link
*/
}
}
echo '<span typeof="v:Breadcrumb">';
echo '<span property="v:title">'.get_the_title().'</span>';
echo '</span>';
}
echo '</div>';
?>
/*End Loop*/
try adding this line of code above the yoast breadcrumb function in your search.php file:
WPSEO_Breadcrumbs::$instance = NULL;
This would be line 22 I believe, and also make sure to use the Yoast breadcrumb function from your question, not the new breadcrumb() function that's there now.
Please let me know if this works!
Full explanation:
The Yoast plugin breadcrumbs functionality is build on the page load, based on the current page as the child. To make it load the right child and parents, you'd need to reset it before you run the function. There is no built-in reset function, however setting the static $instance to NULL should cause the plugin to re-generate its data based on the current global post object which is set while you're looping.
Building upon Yavor's answer I found a way. Been banging my head about it for hours. You can place the backup and restore otuside of the loop though. Here it is:
global $wp_query;
//backup
$old_singular_value = $wp_query->is_singular;
//change
$wp_query->is_singular = true;
//reset
WPSEO_Breadcrumbs::$instance = NULL;
//breadcrumbs
if (function_exists('yoast_breadcrumb')){
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
//restore
$wp_query->is_singular = $old_singular_value;
It fakes the query to make it singular so the newly-refreshed breadcrumbs thinks that this is not the search page but a single post or page or whatever you are displaying as your search results.
Using a plugin to generate breadcrumbs is not really necessary. Here's a simple PHP function you can add to your functions.php file:
function breadcrumbs() {
global $post;
echo "<ul id='breadcrumbs'>";
if (!is_home()) {
echo '<li>Home</li>';
if (is_category() || is_single()) {
echo "<li>" . the_category(' </li><li> ');
if (is_single()) {
echo "</li><li>" . the_title() . "</li>";
}
} elseif (is_page()) {
if($post->post_parent){
foreach ( get_post_ancestors( $post->ID ) as $ancestor ) {
echo '<li>' . get_the_title($ancestor) . '</li>' . get_the_title();
}
} else {
echo "<li>" . get_the_title() . "</li>";
}
}
} elseif (is_tag()) {
single_tag_title();
} elseif (is_day()) {
echo "<li>Archive for " . the_time('F jS, Y') . "</li>";
} elseif (is_month()) {
echo "<li>Archive for " . the_time('F, Y') . "</li>";
} elseif (is_year()) {
echo "<li>Archive for " . the_time('Y') . "</li>";
} elseif (is_author()) {
echo "<li>Author Archive</li>";
} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
echo "<li>Blog Archives</li>";
} elseif (is_search()) {
echo "<li>Search Results for" . the_search_query() . "</li>";
}
echo "</ul>";
}
along with some CSS to style it, customize as you desire
#breadcrumbs {
list-style:none;
margin:5px 0;
overflow:hidden;
}
#breadcrumbs li{
float:left;
}
#breadcrumbs li+li:before {
content: '| ';
padding:0 4px;
}
You can then implement those breadcrumbs on any page you like, including your searchpage.php file or whichever file you use to display search results with this call
<?php breadcrumbs(); ?>
The search pages have a conditional function that can be used. You could always apply that to loading the breadcrumbs. Here is an example:
if ( ! is_search() ) {
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
}
It depends where you are loading the breadcrumbs as well, but this should typically work unless your theme is very unique.
I'm creating a list of articles inside a section, but I'm having troubles getting the images out of my MySQL database. I followed this guide how to store images in MySQL http://forums.mysql.com/read.php?20,17671,27914. This is the code I'm using.
<?php
$result = mysql_query("SELECT * FROM heroes");
while ($row = mysql_fetch_array($result)) {
echo "<article>";
if($row{'Type'} == 'Strength') {
echo "<span class='strength'></span>";
} elseif ($row{'Type'} == 'Agility') {
echo "<span class='agility'></span>";
} else {
echo "<span class='intelligence'></span>";
}
echo "<div>";
echo "<header>"."<h2>"."<a href='javascript:;'>".$row{'Name'}."</a>"."</h2>"."</header>";
if($row{'Image'} != NULL) {
?>
<img src="<?php base64_decode($row{'Image'}); ?>" alt="hero-image" width="200" height="300" />
<?php
} else {
echo '<img src="images/no-image.png" alt="hero-image" width="200" height="300" />';
}
echo "</div>";
echo "</article>";
}
?>
replace your image source with
'data:image/gif;base64,'.base64_decode($row{'Image'});
also use proper mime instead of gif
There are a few things wrong with your code:
You call mysql_fetch_array but then use curly braces which are meant for objects, yet you have an array.
You call base64_decode. This means that you will get binary content into your HTML which won't work. You have to encode it with base64_encode if it is stored in binary form.
The value of the src of a <img> must be a URL, not the content itself. In your case you can use a Data-URL.
I have an unordered list of movies being displayed from the Rotten Tomatoes API in a page called browse (using Laravel Framework). I am trying to use AJAX to load content into a div from a separate file that I have setup as a route called movie when the user clicks on the anchor.
In my routes file I have this:
Route::get('browse', array('as'=>'browse', 'uses'=>'browse#index'));
Route::get('movie', array('as'=>'movie', 'uses'=>'browse#movie'));
Browse View located at /application/views/browse/index.blade.php
$movies = $search_results->movies;
echo '<div id="browse">';
echo '<ul class="movieResults">';
foreach ($movies as $movie) {
echo '<div class="movieCard">';
echo '<li><img src="'. $movie->posters->detailed .'"</li>';
echo '<li class="movieCardInfo">' . $movie->title . '</li>'; // HERE'S WHERE I HAVE THE PROBLEM
echo '</div>';
}
echo '</ul>';
echo '</div>';
Movie View located at /application/views/browse/movie.blade.php. I have dummy text for now
echo '<div class="details">';
echo 'test';
echo '';
Browse Controller
public $restful = true;
public function get_index()
{
return View::make('browse.index')
->with('title', 'Browse Movies');
}
}
Javascript File
$(function() {
$('.movie').click(function() {
$('.details').load(this.href);
return false;
});
});
The project can be found here
Seems like your using the wrong "this"-operator. Should be "$(this)" if it's is a jQuery scripts? (The JavaScript part...)
Also: Ur telling it to add the result from ".load()" into the ".details", but I can't see that you have such a field in your html code?
EDIT
Change the following in /application/views/browse/index.blade.php:
echo '<li class="movieCardInfo">' . $movie->title . '</li>';
echo '<li class="movieCardInfo">' . $movie->title . '<div class="details"></div></li>';
And remove the "div.details" from the response, so the response only returns the text you want in your details.
Then, in the the JavaScript:
$(function() {
$('.movie').click(function() {
$('.details').load($(this).href);
return false;
});
});