I have amp-list element whose src is a search.php file containing product information.
When validating, I'm tld there is no AMP-Access-Control-Allow-Source-Origin header, although I have set one. Here is the php file:
<?php
header('Content-Type: application/json');
// header('AMP-Access-Control-Allow-Source-Origin: http://localhost');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin: https://www-xt2-extenders-com.cdn.ampproject.org');
header('Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin');
header('AMP-Access-Control-Allow-Source-Origin: https://www.xt2-extenders.com');
// filter parameters
$filter = isset($_REQUEST["filter"])?$_REQUEST["filter"]:"";
$products = array(
array(
"name"=>"HXT²",
"price"=>2050.00,
"color"=>"blue",
"description"=>"Super cool super power t-shirt",
"image"=>"../img/hxt-set-500-1.png"
),
array(
"name"=>"DXT²",
"price"=>1980.00,
"color"=>"yellow",
"description"=>"Super cool super power t-shirt",
"image"=>"../img/dxt²-set-500-2.png"
),
array(
"name"=>"SXT²",
"price"=>2050.00,
"color"=>"green",
"description"=>"Super cool super power t-shirt",
"image"=>"../img/sxt²-set-500-2.png"
),
array(
"name"=>"DPXT²",
"price"=>3350.00,
"color"=>"red",
"description"=>"Super cool super power t-shirt",
"image"=>"../img/dpxt²-set-500.png"
)
)
// Filter by subcategory
if(!empty($filter) && !in_array($filter, array('null', 'none'))) {
$filtered = array();
foreach ($products as $product) {
if($product['color']==$filter) {
$filtered[] = $product;
}
}
$products = $filtered;
}
header("HTTP/1.0 200 Ok");
And the html:
<!-- amp-list to fetch and display search results -->
<!-- with amp-bind, the search keywords, filter, and sort options are all bound to the amp-list src URL -->
<!-- This means that whenever one of them changes, amp-list will update and fetch the new URL -->
<amp-list credentials="include"
width="auto" height="600" layout="fixed-height"
src="/amp/templates/search.php?filter="
[src]="'/amp/templates/search.php?filter='+(filter||'')">
<!-- amp-mustache template to display returned results -->
<template type="amp-mustache">
<ul class="related-items">
{{#results}}
<li>
<figure class="related-thumb">
<amp-img src="{{image}}"
width="60" height="60" layout="responsive">
</amp-img>
<figcaption>
<span class="title">{{name}}</span>
<span class="price">€{{price}}</span>
<span class="description">{{description}}</span>
</figcaption>
</figure>
</li>
{{/results}}
</ul>
{{#empty}}
<p>No products matched your search terms</p>
{{/empty}}
</template>
</amp-list>
What do I do wrong? I have read other questions here, and tried to modify my code, but it didn't work.
Try this code in my case it solved an issue
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$http_origin = isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] ? $_SERVER['HTTP_ORIGIN'] : $domain_url;
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: " .$http_origin);
header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
Hope it gonna help you too
Related
I'm trying to do something with my Bootstrap .post-title class.
I want to put an element.style background on my post titles, which calls as a background, to the post featured image, for each post. I've already achieve this, but something went wrong and now isnt working. the only thing i know is must look something like this.
<div class="post-featured" style="background-image:url('upload/<?php the_post_thumbnail( 'wpbs-featured' ); ?>')">
but something in the syntax there is wrong, because it render this characters on HTML. whats going on?
')">
live example: WP Featured post image, as a div background
the_post_thumbnail returns an IMG html tag. So the generated code is
<div class="post-featured" style="background-image:url('upload/<img src="path/to/file.png">')">
Definitely not something that could work... You want the url only, so you should do this:
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'wpbs-featured', true);
<div class="post-featured" style="background-image:url('<?= $thumb_url[0] ?>')">
this is the actual html snippet working.
<?php
$img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full");
$img = $img[0];
?>
<div class="postfeatured" style="<?php if($img){echo 'background:url('.$img.');';} ?>">
<div class="page-header"><h1 class="single-title" itemprop="headline"><?php the_title(); ?></h1>
<h4>
<?php $mykey_values = get_post_custom_values('_aioseop_description');
foreach ( $mykey_values as $key => $value ) {
echo substr("$value",0 ,300); //This will display the first 150 symbols
}?>
</h4>
<hr>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_native_toolbox"></div>
<hr>
</div>
</div>
live example: Design Thinking. Blog de Diseño Gráfico. Picoboero
in magento 1.8.1 i have added a thumbnail image to aw blog posts header and into the aw blog sidebar widget next to the each headline
i did these:
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Form.php
change:
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
to
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
));
In app/code/community/AW/Blog/Block/Manage/Blog/Edit/Tab/Form.php
add
$fieldset->addField('featured_image', 'image', array(
'name' => 'featured_image',
'label' => 'Featured Image'
));
below the line
$fieldset = $form->addFieldset('blog_form', array('legend' => Mage::helper('blog')->__('Post information')));
In app/code/community/AW/Blog/controllers/Manage/BlogController.php
add
if(isset($_FILES['featured_image']['name']) and (file_exists($_FILES['featured_image']['tmp_name']))) {
try {
$uploader = new Varien_File_Uploader('featured_image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
// setAllowRenameFiles(true) -> move your file in a folder the magento way
// setAllowRenameFiles(true) -> move your file directly in the $path folder
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'blogpic'.DS;
$uploader->save($path, $_FILES['featured_image']['name']);
$data['featured_image'] = $_FILES['featured_image']['name'];
}catch(Exception $e) {
}
}
// handle delete image
else {
if(isset($data['featured_image']['delete']) && $data['featured_image']['delete'] == 1)
$data['image_main'] = '';
else
unset($data['featured_image']);
}
below the line
$model = Mage::getModel('blog/post');
And added a "featured_image" column to the aw_blog table in database. Use the type VARCHAR(255) default null and null enable .
and add
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
to
/app/design/frontend/base/default/template/aw_blog/blog.phtml
below line
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
the problem is: the images are saving in right place in media/blogpic but they are not shown in frontend
In your blog.phtml subst
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage() ?>" alt="featuredImage" />
with
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).DS.'blogpic'.DS.$post->getFeaturedImage() ?>" alt="featuredImage" />
Hope it helps.
The easiest way to add a featured image or thumbnail image to the Magento version of AWBlog without coding is as follows:
-In the blog post go to the SHORT CONTENT text field
-In that field enter your image url
<img src="{{media url="wysiwyg/blogimages/myimages/your.jpg"}}" alt="folding chairs" />
-Underneath that enter your blurb that shows
When you save and open the blog post in the blog overview you will see you featured image shows with the content blurb just below it.
I really need some help. I've been banging my head since yesterday morning trying to build a custom design for my girlfriend's baking and cooking recipe blog in wordpress and I'm getting pretty frustrated at this point.
I followed the Lynda.com tutorial on making a custom design in wordpress and I managed to separate the template into header, main section and footer, but I kinda got stuck after that.
Here is a raw html page to see what the site should look like:
http://natalija.co.nf/index.html
And here is where I need some help. I want the main page to be divided into sections, each with a unique ID and data-stellar-background-ratio="0.5" for parallax background effect. These sections would represent categories (cakes, cookies, drinks, dishes etc.). Each category should contain an article with it's own class and data-stellar-ratio="1.5". Within an article there would be an h1 tag with the category title and a jquery slider that would contain links to recipes from that category.
So the structure of a section should look like this:
<section id="teroteikolaci" data-stellar-background-ratio="0.5">
<article class="torteikolaci" data-stellar-ratio="1.5">
<h1>TORTE I KOLAČI</h1>
<div class="wrapper">
<ul class="slider">
<li class="slide">
<a href="#">
<img src="wp-content/themes/Natalija/images/torte-i-kolaci-thumb01.jpg" alt="random">
<div class="bubble">
<h5>Čoko mousse torta 1</h5>
</div>
</a>
</li>
<li class="slide">
<a href="#">
<img src="wp-content/themes/Natalija/images/torte-i-kolaci-thumb02.jpg" alt="random">
<div class="bubble">
<h5>Čoko mousse torta 2</h5>
</div>
</a>
</li>
<li class="slide">
<a href="#">
<img src="wp-content/themes/Natalija/images/torte-i-kolaci-thumb03.jpg" alt="random">
<div class="bubble">
<h5>Čoko mousse torta 3</h5>
</div>
</a>
</li>
</ul>
</div>
</article>
</section>
As I said, I managed to separate the template into header.php, footer.php and home.php,
however I only managed to place the raw html code into home.php which I would like to replace with dynamic content, but I got lost following the guy from the tutorial.
I don't want the categories to be separate pages. I want them all to be displayed within the home page. How do I accomplish this?
I'm new to wordpress so the dashboard kinda confuses me and I'm not familiar with the wordpress php functions so I would really appreciate if someone could give me some guidelines on how to pull this through.
edit:
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
?>
<section id="<?php echo $category->slug; ?>" data-stellar-background-ratio="0.5">
<article class="<?php echo $category->slug; ?>" data-stellar-ratio="1.5">
<h1><?php echo $category->name; ?></h1>
<div class="wrapper">
<ul class="slider">
<?php
}
$args = array (
'post_status' => 'publish',
'category_name' => $category->slug,
'nopaging' => true,
);
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
// begin your slider loops in here
?>
<li class="slide">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<div class="bubble">
<h5><?php echo get_the_title(); ?></h5>
</div>
</a>
</li>
<?php }
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
</ul>
</div>
</article>
</section>
WordPress fetches posts / pages using the WP_Query object (and the nice thing is that it's well documented and you have access to use it and customize it). I would recommend that you create a dedicated loop (using WP_Query) for each section. Let me show you how...
Using "TORTE I KOLAČI" as the first example, just before you begin that section you can create a new loop like so:
// WP_Query arguments allow you to filter out / sort which posts you want
// In this example, I'm just telling WordPress to give me ONLY posts under the
// TORTE I KOLAČI category and NOT to use paging (so you get ALL posts in that
// category without limits)
$args = array (
'post_status' => 'publish',
'category_name' => 'torte_i_kolaci',
'nopaging' => true,
);
// The Query
$custom_query = new WP_Query( $args );
Note: The category_name is actually the slug of the category (and you can find that in the admin section under each category you've defined).
Now it's time to use the $custom_query.
Each section will still have the wrapper code like so:
<section id="teroteikolaci" data-stellar-background-ratio="0.5">
<article class="torteikolaci" data-stellar-ratio="1.5">
<h1>TORTE I KOLAČI</h1>
<div class="wrapper">
<ul class="slider">
Except now you'll switch into PHP and utilize functions such as the_post_thumbnail, get_the_title and get_permalink like so:
<?php
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
// begin your slider loops in here
?>
<li class="slide">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<div class="bubble">
<h5><?php echo get_the_title(); ?></h5>
</div>
</a>
</li>
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
And now that you've looped all your posts, it's time to close out the wrapper...
</ul>
</div>
</article>
</section>
Now you can repeat this pattern for each category you plan to list (SITNI KOLAČI, NAPICI, etc).
Some Notes
I've assumed that your posts are actually posts and not pages (for each item in the loop). If you need pages, you can alter your $args array like so:
$args = array (
'post_type' => 'page',
'post_status' => 'publish',
'category_name' => 'torte_i_kolaci',
'nopaging' => true,
);
Dig into the WP_Query page on the codex to see how flexible these queries can be.
You might want to make your code even more dynamic and easy to maintain by first fetching your categories and then looping those to output the "outer wrapper". WordPress has a function called get_categories that I use all the time. get_categories also has it's own $args array, so take a look at the docs to see what you can do with it. You would structure your code like so:
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
?>
<section id="<?php echo $category->slug; ?>" data-stellar-background-ratio="0.5">
<article class="<?php echo $category->slug; ?>" data-stellar-ratio="1.5">
<h1><?php echo $category->name; ?></h1>
<div class="wrapper">
<ul class="slider">
<?php
}
And now the cool part! You can drive all your inner loops (using WP_Query) from the $category->slug value like so...
$args = array (
'post_status' => 'publish',
'category_name' => $category->slug,
'nopaging' => true,
);
Putting It All Together
So this is what the entire code snippet would look like (I added some comments for some of the braces that help you see where certain loops begin and end).
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
?>
<section id="<?php echo $category->slug; ?>" data-stellar-background-ratio="0.5">
<article class="<?php echo $category->slug; ?>" data-stellar-ratio="1.5">
<h1><?php echo $category->name; ?></h1>
<div class="wrapper">
<ul class="slider">
<?php
$args = array (
'post_status' => 'publish',
'category_name' => $category->slug,
'nopaging' => true,
);
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
// begin your slider loops in here
?>
<li class="slide">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<div class="bubble">
<h5><?php echo get_the_title(); ?></h5>
</div>
</a>
</li>
<?php } // end $custom_query loop
} else {
// no posts found
}
// reset the postdata
wp_reset_postdata();
?>
</ul>
</div>
</article>
</section>
<?php
} // end $categories loop
?>
Hope this helps get you unstuck, have fun!
I am trying to load an Image Slider images from a Custom Post Type image Gallery Feature. For example let say I have an Custom Post Type called banner which I can load images to it's Gallery and I have an HTML code like this:
<div class="item active">
<img src="assets/img/ban1r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
<div class="item active">
<img src="assets/img/ban2r.jpg" alt="">
<div class="carousel-caption">
slide 1
</div>
</div>
Can you please let me know how I can use the custom WP_Query to retrive the images from the custom post and load them into slider instead of above HTML?
So far I have done something like this but it is not displaying any image!
<?php
$args = array( 'post_type' => 'banner');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$gallery = get_post_gallery_images($post);
foreach( $gallery as $image ) {
echo '<div class="item active">';
echo '<img src="' . $image . '">';
echo '</div>';
}
endwhile;
?>
I tried something like this before 2 months ago, and working great for me.
global $wpdb;
$query = "select * from $wpdb->posts
where
post_type = 'banner' and
post_status = 'publish'";
$results = $wpdb->get_results($query, ARRAY_A);
foreach( $results as $result ){
echo '<div id="'.$result['ID'].'" class="listen">';
echo get_the_post_thumbnail( $result['ID'], array(200, 200) );
</div>';
}
Take a look on get_the_post_thumbnail
What would be to the easiest way to do the following?
Random Input:
check out my new video here http://www.youtube.com/watch?v=123abc
or here http://youtu.be/123abc
here is my new wallpaper http://somepage.com/fRDTk.jpg
and my new homepage http://google.com
Output:
check out my new video here
<a class="youtube" href="http://www.youtube.com/watch?v=123abc">
http://www.youtube.com/watch?v=123abc</a>
or here
<a class="youtube" href="http://youtu.be/123abc">
http://youtu.be/123abc</a>
here is my new wallpaper
<a class="image" href="http://somepage.com/fRDTk.jpg">
http://somepage.com/fRDTk.jpg</a>
and my new homepage
<a class="iframe" href="http://google.com">
http://google.com</a>
What is the easiest way to autolink and also add a specific class depending on the link? (image, youtube, other)
I put this together already but its failing miserably.
<?php
foreach ($imgur->captions->item as $comment) {
$co = $comment->caption;
$linkstring = preg_replace('/(http|ftp)?+(s)?:?(\/\/)?+(www.)?((\w|\.)+)+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|be|info|co)+(\/)?(\S+)?/i', '<a rel="fancybox fancybox.iframe" href="\0">\0</a>', $co );
if(preg_match('/^http:\/\/(?:www\.)?(?:youtube.com|youtu.be)\/(?:watch\?(?=.*v=([\w\-]+))(?:\S+)?|([\w\-]+))$/i', $co, $vresult)) {
$pattern = "/(http|ftp)?+(s)?:?(\/\/)?+(www.)?((\w|\.)+)+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|be|info|co)+(\/)?(\S+)?/i";
$replacement = '<a class="fancybox-media" href="\0">\0</a>';
$text = preg_replace($pattern, $replacement, $co);
$type= 'youtube';
}
elseif(preg_match('/(http(s?):)?([\/.|\w|\s])*\.(?:jpg|gif|png|jpeg|bmp)/i', $co, $vresult)) {
$pattern = "/(http|ftp)?+(s)?:?(\/\/)?+(www.)?((\w|\.)+)+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|be|info|co)+(\/)?(\S+)?/i";
$replacement = '<a class="fancybox" href="\0">\0</a>';
$text = preg_replace($pattern, $replacement, $co);
$type= 'image';
}
else {
$pattern = "/(http|ftp)?+(s)?:?(\/\/)?+(www.)?((\w|\.)+)+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|be|info|co)+(\/)?(\S+)?/i";
$replacement = '<a class="fancybox fancybox.iframe" href="\0">\0</a>';
$text = preg_replace($pattern, $replacement, $co);
$type = 'none';
}
echo "<div class=\"icomment\">
<p class=\"icomment\">“",$text,"” -",$comment->author,"</p>
</div>";
}
?>
I have been messing around with it a lot and just want to scrap it. Hoping there is an easier way to do this.
$patterns = array(
array('pattern'=>'/mypattern/','replaceWith'=>'myreplacement\0','addClass'=>'myclass'),
array('pattern'=>'/mypattern/','replaceWith'=>'myreplacement\0','addClass'=>'myclass'),
);
foreach($patterns as $pattern) {
// .... do your thing here... once... for every possibility described in array above.
}