如何按标签而不是标题进行过滤

时间:2018-05-07 03:04:12

标签: javascript html search filter hubspot

新手程序员正在寻找一些关于我试图在hubSpot中学习阅读和修复的代码的建议。我想获取代码来按标签搜索博客帖子,而不仅仅是标题。任何意见,将不胜感激。我将在下面发布代码。由于我对数据库的经验很少,所以我很感激任何解释。谢谢!

<div class="body-container-wrapper">
    <div class="body-container container-fluid">

<div class="row-fluid-wrapper row-depth-1 row-number-1 ">
<div class="row-fluid ">
<div class="span12 widget-span widget-type-cell flush-rows" style="" data-widget-type="cell" data-x="0" data-w="12">

<div class="row-fluid-wrapper row-depth-1 row-number-2 ">
<div class="row-fluid ">
<div class="span12 widget-span widget-type-cell container" style="" data-widget-type="cell" data-x="0" data-w="12">

<div class="row-fluid-wrapper row-depth-1 row-number-3 ">
<div class="row-fluid ">
<div class="span12 widget-span widget-type-raw_jinja " style="" data-widget-type="raw_jinja" data-x="0" data-w="12">
{# Instead of trying to sort the contents directly, make a list of just event dates and post ids. #}
{% set events = utility.event_looper(contents, (topic or simple_list_page or blog_author))|split(',')|sort(simple_list_page or topic == 'past-events' or topic == 'webinar', True) %}
{% set months = utility.month_looper(contents, (topic or simple_list_page or blog_author))|split(',')|sort(simple_list_page or topic == 'past-events' or blog_author, True)|unique %}
{% set page_number = request.query_dict.page|int or 1 %}
{% set posts_per_page = 1000 if simple_list_page else 12 %}
{% set max_pages = (events|count / posts_per_page)|round(0, 'ceil') %}
{% if page_number > max_pages %}
    {% set page_number = max_pages %}
{% endif %}
{% set offset = (page_number - 1) * posts_per_page %}
{% set base_url = group.absolute_url ~ '/' %}
{% if current_month %}
    {% set topic = current_month %}
{% endif %}
{% if topic %}
    {% set base_url = base_url ~ 'topic/' ~ topic %}
{% endif %}
{% if blog_author %}
    {% set base_url = base_url ~ 'author/' ~ blog_author.slug %}
{% endif %}
{% if current_month %}
    {% set topic = current_month %}
{% endif %}


{% set month_labels = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
]%}

{% if is_listing_view %}

<div class="padded-section padded-section--half">
    <div class="events-listing">
        <div class="filters filters--blog">
            <h3 class="filters__title">Explore Events</h3>
            <div class="filters__controls">
                {% set current_month = request.query_dict.month %}
                {% if current_month or topic %}
                    <a href="{{ group.absolute_url }}" class="filters__item filters__item--clear">View All</a>
                {% endif %}
                <div class="filters__item filters__item--filter filters__item--filter--topics select-nav">
                    <span class="select-nav__label" title="Type">
                        Type
                    </span>
                    <div class="select-nav__options">
                        <a href="http://www.----.com/events/topic/webinar">Webinar</a>
                        <a href="http://www.----.com/events/topic/conference">Conference</a>
                    </div>
                </div>
                {% unless current_month or topic %}
                <div class="filters__item filters__item--filter filters__item--filter--topics select-nav">
                    <span class="select-nav__label" title="{{ topic_group.label_plural }}">
                        {% if current_month and month_labels[current_month] %}{{ current_month.label }}: {{ month_labels[current_month] }}{% else %}Months{% endif %}
                    </span>

                    <div class="select-nav__options">
                        {% for month in months %}
                            {% set year = month[0:4] %}
                            {% set month_value = month[4:6] %}
                            {% set month_index = month[4:6]|trim|int - 1 %}
                            {% set month_label = month_labels[month_index] %}
                            <a href="http://www.----.com/events/topic/{{ month_value }}{{ year }}">{{ month_label }} {{ year }}</a>
                        {% endfor %}
                    </div>
                </div>
                {% endunless %}
                {{ components.search_form('https://www.----.com/search', 'blog-search', current_search, 'filters__item filters__item--search', 'q') }}
            </div>
        </div>
        {% if events %}
            <div class="event-listing clearfix">
                {% for event in events %}
                    {% set post_id = event|split(':', 2)|last %}
                    {% set content = blog_post_by_id(post_id) %}
                    {% if simple_list_page or (loop.index > offset and loop.index <= offset + posts_per_page) %}
                        {{ components.event_thumbnail_blog_post(content) }}
                    {% endif %}
                {% endfor %}
            </div>
            <nav class="blog-listing__nav listing-nav">
                {% if page_number > 1 %}
                    <a href="{{ base_url }}{% if page_number > 2 %}?page={{ page_number - 1 }}{% endif %}" class="listing-nav__item listing-nav__item--prev">Previous</a>
                {% endif %}
                {% if simple_list_page or topic or blog_author %}
                    <a href="{{ group.absolute_url }}" class="listing-nav__item listing-nav__item--all">View Upcoming</a>
                {% else %}
                    <a href="{{ group.absolute_url }}/topic/past-events" class="listing-nav__item">View Past Events</a>
                {% endif %}
                {% endif %}
                {% if page_number < max_pages %}
                    <a href="{{ base_url }}?page={{ page_number + 1 }}" class="listing-nav__item listing-nav__item--next">Next</a>
                {% endif %}
            </nav>
        {% else %}
            <div class="events-listing__error">
                <p><em>Couldn't find any upcoming events!</em></p>
                {% if blog_author or topic %}
                    <p><a href="{{ group.absolute_url }}">View Upcoming</a></p>
                {% endif %}
            </div>
        {% endif %}
    {% endif %}
    </div>
</div>
{% endif %}
</div><!--end widget-span -->

1 个答案:

答案 0 :(得分:0)

首先,它是embedded javaScript file EJS,如果这可以帮助您翻译那里发生的事情。很多看起来像变量设置和下拉菜单。

但一般来说,您通过API路由从数据库获取信息。例如,您可以找到同一作者的其他帖子的块是通过GET路由到yourSiteURL.com/author/edgar%20allen%20poe或查询搜索,如yoursite.com/posts?tag='gothic'您将请求这些GET路由并接收数据。

如果这只是一个模板而且您必须连接到自己的模板,我会查看您尝试连接的数据库的API文档或查看有关设置自己的数据库。