I'm trying to filter my blog listing page by topic when desired. I know I'm probably over thinking this, but for whatever reason I cant figure out how to get the listing page to show only the desired topic chosen. I just added the {% if topic %} statement to see if that would fix my propblem, but it wont show the topic posts - it's left blank as seen in the screenshot below.
Archive and topic filtered listings default to a "simple listing page". You can negate this by simply removing the red if statement. The statement is saying "if not a simple list page" (i.e. normal listing) then use this markup, else (i.e. posts by date or topic) use this markup but there is no markup there so your listing is blank.
1) I removed removed the {if not_simple_listing} declaration since I really only care about showing all posts and then filtering by topic when requested - that didnt work for me. The result: shows all blog posts no matter the topic chosen.
2) Next I duplicated the <article> element into the blank else statement to see if I could at least get something to appear - again nothing showed. Result: still blank page topic page.
3) I removed the {if topic} statement and the {if not_simple_listing} statement to see if that would work - no luck. Result: shows all blog posts no matter the topic chosen.
All I'm trying to do is show only the topic chosen from the all posts listings page. No formating changes will happen only the filtering of topics is desired.
I have built tons of blogs using coded files so there shouldn't be a problem.
You have this at the top of your code:
{% set posts = blog_recent_posts('XXXX', 10) %}
{% set topic_posts = blog_recent_topic_posts('XXXX', topic.slug, 10) %}
{% set topics = blog_topics('XXXX', 10) %}
but I'm not seeing where you are referencing these variables in your code so that shouldn't be a problem either. actually you don't even need these since it doesn't seam you are using them. To use them you would need to loop through them like:
{% set posts = blog_recent_posts('XXXX', 10) %}
{% set topic_posts = blog_recent_topic_posts('XXXX', topic.slug, 10) %}
{% set topics = blog_topics('XXXX', 10) %}
{% for post in posts %}
{% endfor %}
{% for topic in topics %}
{% endfor %}
etc.
Your not looping through these, your looping through your normal contents loop:
{% for content in contents %}
{% endfor %}
the "topic" variable is automatically assigned based on the topic at the end of the url ".../topic/amazon" so is blank or undefined if not filtering by topic. You don't need to use this in your loop. You can use this to change the title of your blog or something:
{% if topic is defined %}
posts about {{ topic.name }}
{% else %}
All Posts
{% endif %}
But all you need for your listing page is:
{% for content in contents %}
{# markup for your list items #}
{% endfor %}
and no matter how you filter your listing page, or don't, it will always use the markup within this contents loop. There is no need check for a topic or etc. unless you are wanting to change the markup of your list item when filtering.
just to reiterate, the:
{% if not simple_list_page %}
{# Markup to use for original listing page, no filtering #}
{% else %}
{# Markup to use if filtering by topic, i.e. simple list page #}
{% endif %}
condition inside of the default for contents loop will trip you up if you don't remove it or adjust it to your needs.