How do I replace a blog list of index
example: mysite.com to mysite.com/blog
I have copied from the index and make myste.com/blog.html , but it does not work
---
layout: default
---
<div class="home">
<div class="site-header-container {% if site.cover %}has-cover{% endif %}" {% if site.cover %}style="background-image: url({{ site.cover | prepend: site.baseurl }});"{% endif %}>
<div class="scrim {% if site.cover %}has-cover{% endif %}">
<header class="site-header">
<h1 class="title">{{ site.title }}</h1>
{% if site.subtitle %}<p class="subtitle">{{ site.subtitle }}</p>{% endif %}
</header>
</div>
</div>
<div class="wrapper">
<ul class="post-list">
{% for post in paginator.posts %}
<li>
<h2>
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</h2>
<section class="post-excerpt" itemprop="description">
<p>{{ post.content | strip_html | truncatewords: 50 }}</p>
</section>
<section class="post-meta">
<div class="post-date">{{ post.date | date: "%B %-d, %Y" }}</div>
<div class="post-categories">
{% if post.categories.size > 0 %}in {% for cat in post.categories %}
{% if site.jekyll-archives %}
{{ cat | capitalize }}{% if forloop.last == false %}, {% endif %}
{% else %}
<span>{{ cat | capitalize }}</span>{% if forloop.last == false %}, {% endif %}
{% endif %}
{% endfor %}{% endif %}
</div>
</section>
</li>
{% if forloop.last == false %}
<hr>
{% endif %}
{% endfor %}
</ul>
<nav class="pagination" role="navigation">
<p>
{% if paginator.next_page %}
<a class="newer-posts" href="{{ site.baseurl }}/page{{paginator.next_page}}">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-left fa-stack-1x fa-inverse"></i>
</span>
</a>
{% else %}
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-left fa-stack-1x fa-inverse"></i>
</span>
{% endif %}
<span class="page-number">Page {{ paginator.page }} of {{ paginator.total_pages }}</span>
{% if paginator.previous_page %}
{% if paginator.page == 2 %}
<a class="newer-posts" href="{% if site.baseurl %}{{ site.baseurl }}{% endif %}/">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
</a>
{% else %}
<a class="newer-posts" href="{{ site.baseurl }}/page{{paginator.previous_page}}">
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
</a>
{% endif %}
{% else %}
<span class="fa-stack fa-lg">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-angle-double-right fa-stack-1x fa-inverse"></i>
</span>
{% endif %}
</p>
<p>
View All Posts by Category
</p>
</nav>
</div>
</div>
Open your config file, and set baseurl as /blog
baseurl: "/blog"
And use prepend:site.baseurl everywhere, just like you have used in above code
{{ site.baseurl }}/category/{{ cat }}
Related
I have this query to display rating and it works fine
$ads = Advert::find(151);
$this['userAverageRating'] = $ads->ratings()->avg('rating');
to display it in twig i have this that works too
<div align="left" style="font-size: 12px;">
{% if userAverageRating %}
{% for i in range(1,5) %}
{% if userAverageRating >= max(0, i-0.25) %}
<span style="color: orange" class="fa fa-star"></span>
{% elseif (userAverageRating > (i-0.75)) %}
<span style="color: orange" class="fa fa-star-half-o"></span>
{% else %}
<span style="color: orange" class="fa fa-star-o"></span>
{% endif %}
{% endfor %}
<span><b>{{ userAverageRating|round(1, 'floor') }}/5</b></span>
{% else %}
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span style="font-size: 12px"><b></b></span>
{% endif %}
</div>
The above twig tag is in a twig foreach
{% for ad in ads %}
{{ ad.title }}
{{ ad.description }}
...
//the above twig tag here
{% endfor %}
My main problem is that the rating of ad id "151" displays on all the ad foreach results, instead of just ad with id 151. Any ideas why this is and how to fix it
Looking at your php variable $ads = Advert::find(151); this will literally return the advert with id = 151.
try changing this to $ads = Advert::all(); or $ads = Advert::get();
if you need the rating relation attached to each of the Advert results, you could also eager load this.
$ads = Advert:with('ratings')->get();
Then run your logic against ads.rating in twig.
Consider calculating what you need in your component before sending it to the front end. then just looping over the single result.
Two ways to solve this issue and I think the first way is more elegant. Some things to note is I am guessing on how to work with your models. So you might have to adjust the if ($ad->ratings()->first) I am assuming it will return null if there isn't something there. The second way is closer to your logic now but you need to add the id (or something unique) so you can use twig to check ids like {% if userAverageRating and ad.id == userAverageRating.id %}.
1: Foreach and modify the collections of every ad to average the rating.
$ads = Advert::all();
foreach ($ads as $ad) {
if ($ad->ratings()->first) {
$ad->averageRating = $ad->ratings()->avg('rating');
}
else {
$ad->averageRating = null;
}
}
$this['ads'] = $ads;
//Twig Script
{% if ad.averageRating %}
{% for i in range(1,5) %}
{% if ad.averageRating >= max(0, i-0.25) %}
<span style="color: orange" class="fa fa-star"></span>
{% elseif (ad.averageRating > (i-0.75)) %}
<span style="color: orange" class="fa fa-star-half-o"></span>
{% else %}
<span style="color: orange" class="fa fa-star-o"></span>
{% endif %}
{% endfor %}
<span><b>{{ ad.averageRating|round(1, 'floor') }}/5</b></span>
{% else %}
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span style="font-size: 12px"><b></b></span>
{% endif %}
2: Collect the ratings in an array with ad ID.
$ads = Advert::all();
$ratings = [];
foreach ($ads as $key => $ad) {
if ($ad->ratings()->first) {
$ratings[$key] = [ 'id' = $ad->id, 'rating' = $ad->ratings()->avg('rating') ];
}
else {
$ratings[$key] = null;
}
}
$this['userAverageRating'] = $ratings;
//Twig Script
{% if userAverageRating and ad.id == userAverageRating.id %}
{% for i in range(1,5) %}
{% if userAverageRating >= max(0, i-0.25) %}
<span style="color: orange" class="fa fa-star"></span>
{% elseif (userAverageRating > (i-0.75)) %}
<span style="color: orange" class="fa fa-star-half-o"></span>
{% else %}
<span style="color: orange" class="fa fa-star-o"></span>
{% endif %}
{% endfor %}
<span><b>{{ userAverageRating|round(1, 'floor') }}/5</b></span>
{% else %}
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span class="fa fa-star-o"></span>
<span style="font-size: 12px"><b></b></span>
{% endif %}
I am using Bootstrap-Carousel.
Unfortunately, the data from front-matter is not being rendered.
index.html:
...
carousel:
a:
image: home/athenaBeta.jpeg
text: random text 1
b:
image: home/transport.jpeg
text: |
random text 2
c:
image: home/coffee.jpeg
text: |
random text 3
---
{% include hero-carousel.html %}
...
hero-carousel.html:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
{% capture image %}
{% assign img = news.image %}
{% endcapture %}
<div class="item img-cover img-fixed {% if forloop.index == 0 %}active{% endif %}" style="background-image:url({{ image }})">
<h2>{{ news.text }}</h2>
</div>
{% capture i %}{{ i | plus:1 }}{% endcapture %}
{% endfor %}
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
It renders the three slides, however, none of the images or text is rendered. The output I get in browser is as below:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url()">
<h2></h2>
</div>
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
When you loop in page.caroussel, you receive things like :
{{ news | inspect }}
==> ["a", {"image"=>"home/athenaBeta.jpeg", "text"=>"random text 1"}]
which is an array containing two elements.
In order to reach your image, you can do {% assign img = news[1].image %}, but you'd better refactor a little :
...
carousel:
- image: home/athenaBeta.jpeg
text: random text 1
- image: home/transport.jpeg
text: |
random text 2
- image: home/coffee.jpeg
text: |
random text 3
---
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
<div class="item img-cover img-fixed {% if forloop.first %}active{% endif %}" style="background-image:url('{{ news.image }}')">
<h2>{{ news.text }}</h2>
</div>
{% endfor %}
</div>
When I compare in if the post.category is as if there was a post that is the variable is more when I put {{post.category}} it prints the name. It's like if he did not exist in most if I put in if site.post.category handle all values. The problem is that I want to get the current post to compare if that category. I want to list the posts by category.
<div class="posts">
{% for post in site.posts %}
{% if post.category == Eventos %}
<hr>
<div class="post">
<h1 class="post-title">
<a href="{{ site.url }}{{post.url}}">
{{ post.title }}
</a>
</h1>
<span class="post-date">{{ post.date | date_to_string }} / {{ post.category }}</span> {{ post.excerpt }}
<h6>Leia mais...</h6>
</div>
{% endif %}
{% endfor %}
</div>
Try with categories !
{% if post.categories | contains: 'Eventos' %}
I'm trying to make only the available product variants visible in drop downs for products like this one. For example, say you choose 2012 in the first drop down, it would only show the available choices in the second. If you then chose Wed 25th July in the second, it would only show the available variants in the third. At the minute it shows all choices and states 'We don't offer the product in this combination' for an unavailable choice.
So far, my product.liquid page has this code:
<div class="col-7 product-description clearfix">
<h1>{{ product.title }}</h1>
{{ product.description }}
{% include 'addthis' %}
<br/><br/>
{% if product.available %}
{% if product.variants.size > 1 %}
<!-- If the product only has MULTIPLE OPTIONS -->
<form action="/cart/add" method="post" class="product-variants">
<div id="options">
<select id="product-select" name='id'>
{% for variant in product.variants %}
<option value="{{ variant.id }}">{{ variant.title }}</option>
{% endfor %}
</select>
<div class="select-wrapper">
<label for="region">DVD Region</label>
<select id="color" required>
<option value="NTSC">NTSC</option>
<option value="PAL/SECAM" selected="selected">PAL/SECAM</option>
</select>
</div>
<p>Click Here find out more about your region.</p>
</div> <!-- options -->
<div class="price-field"></div>
<input type="submit" name="add" value="Add to cart" id="purchase" />
</form>
{% else %}
<!-- If the product only has ONE variant -->
<form action="/cart/add" method="post" class="product-variants">
<div class="price-field"> {{ product.price | money }}</div>
<input type="submit" name="add" value="Add to cart" id="purchase" />
<input type="hidden" id="{{ variant.id }}" name="id" value="{{ product.variants[0].id }}" /> <!-- passes variant id -->
</form>
{% endif %}
{% else %}
<p>This product is not available</p>
{% endif %}
</div><!-- .col-7 -->
<div class="col-5 last product-thumbs">
<ul>
{% for image in product.images %}
{% if forloop.first %}
<li class="featured-image" >
<a class="zoom " href="{{ image | product_img_url: 'large' }}" title="{{ product.featured_image.alt | escape }}">
<img src="{{ image | product_img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}" />
</a>
</li>
{% else %}
<li>
<a class="zoom" href="{{ image | product_img_url: 'large' }}" title="{{ image.alt | esacpe }}">
<img class="" src="{{ image | product_img_url: 'small' }}" alt="{{ image.alt | escape }}" />
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div><!-- .col-5 -->
<script type="text/javascript">
// <![CDATA[
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('#purchase').removeClass('disabled').removeAttr('disabled'); // remove unavailable class from add-to-cart button, and re-enable button
jQuery('#purchase').fadeIn();
jQuery('.price-field').html(Shopify.formatMoney(variant.price, "{{shop.money_with_currency_format}}")); // update price field
} else {
// variant doesn't exist
jQuery('#purchase').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
jQuery('#purchase').fadeOut();
var message = variant ? "Sold Out" : "We don't offer the product in this combination";
jQuery('.price-field').text(message); // update price-field message
}
};
// initialize multi selector for product
jQuery(document).ready(function() {
new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: selectCallback });
{% assign found_one_in_stock = false %}
{% for variant in product.variants %}
{% if variant.available and found_one_in_stock == false %}
{% assign found_one_in_stock = true %}
{% for option in product.options %}
jQuery('.single-option-selector:eq(' + {{ forloop.index0 }} + ')').val({{ variant.options[forloop.index0] | json }}).trigger('change');
{% endfor %}
{% endif %}
{% endfor %}
$('#options div').addClass("selector-wrapper");
{% if product.options.size == 1 %}
$(".selector-wrapper").append("<label>{{ product.options.first }}</label>");
{% endif %}
});
// ]]>
</script>
Any help?
With Shopify I am trying to alter my product template to display a dropdown select list instead of radio buttons for my product variants. I managed to do this but when you try and add a product to the cart from the list it says, "No variant ID was passed."
Here is the code for their radio buttons:
<ul id="product-variants">
{% for variant in product.variants %}
<li>
{% if variant.available %}
<input type="radio" name="id" value="{{variant.id}}" id="radio_{{variant.id}}" style="vertical-align: middle;" {%if forloop.first%} checked="checked" {%endif%} />
<label for="radio_{{variant.id}}"><span class="sku">{{ variant.sku }}</span> {%if variant.title != 'Default' %}{{ variant.title }} for {%endif%} <span class="price">{{ variant.price | money_with_currency }}</span></label>
{% else %}
<del style="margin-left: 26px">{{ variant.title }}</del> <span>Sold Out!</span>
{% endif %}
</li>
{% endfor %}
</ul>
Here is the code for my dropdown select at this point:
<select id="product-variants">
{% for variant in product.variants %}
<li>
{% if variant.available %}
<option value="{{variant.id}}" selected="selected"><span class="sku">{{ variant.sku }}</span> {%if variant.title != 'Default' %}{{ variant.title }} for {%endif%} <span class="price">{{ variant.price | money_with_currency }}</span></option>
{% else %}
<del style="margin-left: 26px">{{ variant.title }}</del> <span>Sold Out!</span>
{% endif %}
</li>
{% endfor %}
</select>
Thanks,
Wade
https://help.shopify.com/themes/development/templates/product-liquid
This wiki had the answer to my question.