showing tag beside catagory

时间:2015-07-12 作者:Rohan Zakie

谢谢你的指导,这是我要学习的最后一件事,

我使用的是今日新闻wordpress主题,因为在您的帮助下,我已将我的流程从类别转移到基于标记的归档,我的主题为我提供了显示特定类别帖子列表的短代码,如下所示

[博客1项=1类=编辑]

这里的“专栏”是我的分类,它显示如下

(在下面的链接中添加http://in)

s15。postimg公司。组织/g1s8k8cmz/图像。jpg公司

s15。postimg公司。org/oy30o6397/image。jpg公司

如果你需要,我可以附加主题文件。PS,我们的目标是将基于类别的排序替换为基于标记的排序,就像您之前帮助我的那样。

生成此简短信息的代码是http://pastebin.com/qpLyeSsF

    <?php
$queried_object = get_queried_object();
$term = $queried_object->name;
add_shortcode("blog1", "blog_one");



function blog_one($atts, $content) {

    extract(shortcode_atts(array(

        "items" => 4,

        "cat" => null,

        "id" => null,

        "nav" => false,

        "order" => "desc",

        "orderby" => "DATE",

        "events" => null

    ), $atts));

    $order       = strtoupper($order);

    $items_count = 0;

    $items_src   = null;

    if ($id == null) {

        $query          = array(

            \'orderby\' => $orderby,

            \'order\' => $order,

            \'posts_per_page\' => $items,

            \'category_name\' => $cat

        );

        $wp_query_event = new WP_Query($query);

    }

    $items_src .= \'

<div id="short-one" class="fixed">\';

    while ($wp_query_event->have_posts()):

        $wp_query_event->the_post();

        global $post;

        $image_id = get_post_thumbnail_id();

        $cover    = wp_get_attachment_image_src($image_id, \'short-one\');

        $no_cover = get_template_directory_uri();

        $category = get_the_category();

        $vimeo    = get_post_meta($post->ID, "post_vimeo", true);

        $youtube  = get_post_meta($post->ID, "post_youtube", true);

                $author   = get_the_author_meta(\'ID\');

        $items_src .= \'

        <div class="short-one-art">

                <div class="short-one-cover">\';

        if ($vimeo or $youtube) {

            $items_src .= \'<a href="\' . get_permalink() . \'"><div class="short-one-video"></div></a>\';

        }

        $items_src .= \'

                        <a href="\' . get_permalink() . \'">\';

        if ($image_id) {

            $items_src .= \'<img src="\' . $cover[0] . \'" alt="\' . get_the_title() . \'" />\';

        } else {

            $items_src .= \'<img src="\' . $no_cover . \'/images/no-cover/short-one.png" alt="no-cover" />\';

        }

        $items_src .= \'</a>

                        <div class="comment-bubble">

                                <span class="comment-count">\' . get_comments_number() . \'</span>

                        </div>\';

        if ($cat != null) {

        } else {

            $items_src .= \'            

                        <div class="slider-left-cat">\' . $category[0]->cat_name . \'</div>\';

        }

        $items_src .= \'</div>

                <h2><a href="\' . get_permalink() . \'">\' . get_the_title() . \'</a></h2>

                <div class="short-one-info">\' . get_the_date(\'F jS, Y\') . \' | by <a href="\' . get_author_posts_url($author) . \'">\' . get_the_author() . \'</a> | <a href="\'.get_category_link($category[0]->cat_ID).\'">\'. $category[0]->cat_name .\'</a></div>

                \' . get_excerpt(230) . \'

        </div><!-- end .short-one-art -->\';

    endwhile;

    wp_reset_query();

    $items_src .= \'

</div><!-- end #short-one -->

\';

    return $items_src;

}
如果你需要更多线索找到这个罪犯,请告诉我

谢谢

1 个回复
最合适的回答,由SO网友:terminator 整理而成

将此代码粘贴到您提供的代码旁边我还没有测试代码,但它应该可以做到这一点。。。

你用这个的地方[blog1 items=1 cat=op-ed] 将此替换为此[blogtag items=1 tag=china]

  <?php
$queried_object = get_queried_object();
$term = $queried_object->name;
add_shortcode("blogtag", "blog_tag");



function blog_tag($atts, $content) {

    extract(shortcode_atts(array(

        "items" => 4,

        "tag" => null,

        "id" => null,

        "nav" => false,

        "order" => "desc",

        "orderby" => "DATE",

        "events" => null

    ), $atts));

    $order       = strtoupper($order);

    $items_count = 0;

    $items_src   = null;

    if ($id == null) {

        $query          = array(

            \'orderby\' => $orderby,

            \'order\' => $order,

            \'posts_per_page\' => $items,

            \'tag\' => $tag

        );

        $wp_query_event = new WP_Query($query);

    }

    $items_src .= \'

<div id="short-one" class="fixed">\';

    while ($wp_query_event->have_posts()):

        $wp_query_event->the_post();

        global $post;

        $image_id = get_post_thumbnail_id();

        $cover    = wp_get_attachment_image_src($image_id, \'short-one\');

        $no_cover = get_template_directory_uri();

        $tag      = get_the_tags();

        $vimeo    = get_post_meta($post->ID, "post_vimeo", true);

        $youtube  = get_post_meta($post->ID, "post_youtube", true);

        $author   = get_the_author_meta(\'ID\');

        $items_src .= \'

        <div class="short-one-art">

                <div class="short-one-cover">\';

        if ($vimeo or $youtube) {

            $items_src .= \'<a href="\' . get_permalink() . \'"><div class="short-one-video"></div></a>\';

        }

        $items_src .= \'

                        <a href="\' . get_permalink() . \'">\';

        if ($image_id) {

            $items_src .= \'<img src="\' . $cover[0] . \'" alt="\' . get_the_title() . \'" />\';

        } else {

            $items_src .= \'<img src="\' . $no_cover . \'/images/no-cover/short-one.png" alt="no-cover" />\';

        }

        $items_src .= \'</a>

                        <div class="comment-bubble">

                                <span class="comment-count">\' . get_comments_number() . \'</span>

                        </div>\';

        if ($tag != null) {

        } else {

            $items_src .= \'            

                        <div class="slider-left-cat">\' . $tag[0]->name . \'</div>\';

        }

        $items_src .= \'</div>

                <h2><a href="\' . get_permalink() . \'">\' . get_the_title() . \'</a></h2>

                <div class="short-one-info">\' . get_the_date(\'F jS, Y\') . \' | by <a href="\' . get_author_posts_url($author) . \'">\' . get_the_author() . \'</a> | <a href="\'.get_tag_link($tag[0]->term_id).\'">\'. $tag[0]->name .\'</a></div>

                \' . get_excerpt(230) . \'

        </div><!-- end .short-one-art -->\';

    endwhile;

    wp_reset_query();

    $items_src .= \'

</div><!-- end #short-one -->

\';

    return $items_src;

}

结束

相关推荐

如何在没有Java脚本的情况下将HTML5‘Required’属性添加到wp_Dropdown_Categories()?

我正在使用wp_dropdown_categories() 用于填充<select> 具有自定义分类术语的字段。如果代码如下所示:<?php $args = array( \'show_option_none\' => __( \'Select one\', \'text-domain\' ), \'taxonomy\' => \'my_tax\', \'id\'