Пример #1
0
/**
 * Generates HTML for [adverts_list] shortcode
 * 
 * This function replaces default [adverts_list] callback and
 * adds author header before the listings.
 *
 * @param array $atts Shorcode attributes
 * @since 1.0
 * @return string Fully formatted HTML for adverts list
 */
function ads_by_author_list($params)
{
    $html = "";
    $params["search_bar"] = "disabled";
    $author = get_user_by("id", adverts_request("posted_by"));
    ob_start();
    ?>
    <style type="text/css">
        .ads-by-author.adverts-options {
            padding: 0.5em 1em;
        }
        .ads-by-author.adverts-options .author-logo {
            float: left; 
            height: 48px;
            width: 64px;
        }
        .ads-by-author.adverts-options .author-logo > img {
            border-radius: 50%;
        }
        .ads-by-author.adverts-options .author-data {
            line-height: 24px;
        }
    </style>
    <div class="ads-by-author adverts-options">
        <div class="author-logo">
            <?php 
    echo get_avatar($author->user_email, 48);
    ?>
        </div>
        <div class="author-data">
            <strong><?php 
    esc_html_e($author->display_name);
    ?>
</strong><br/>
            <?php 
    esc_html_e(date_i18n(get_option("date_format"), strtotime($author->user_registered)));
    ?>
        </div>
    </div>        
    <?php 
    $html .= ob_get_clean();
    $html .= shortcode_adverts_list($params);
    return $html;
}
Пример #2
0
/**
 * Dynamically replace post content with Advert template.
 * 
 * This function is applied to the_content filter.
 * 
 * @global WP_Query $wp_query
 * @param string $content
 * @since 0.1
 * @return string
 */
function adverts_the_content($content)
{
    global $wp_query;
    if (is_singular('advert') && in_the_loop()) {
        ob_start();
        $post_id = get_the_ID();
        include ADVERTS_PATH . 'templates/single.php';
        $content = ob_get_clean();
    } elseif (is_tax('advert_category') && in_the_loop()) {
        $content = shortcode_adverts_list(array("category" => $wp_query->get_queried_object_id()));
    }
    return $content;
}