Tips on Creating Trending in WordPress Without Plugins - KhalistaBlog -->
Skip to content Skip to sidebar Skip to footer

Tips on Creating Trending in WordPress Without Plugins

Tips on Creating Trending in WordPress Without Plugins - Actually a way to make a trending in wordpress it is very easy because there are many provided plugins in the special for it. But if I am going to try to make it without plugins, or like news websites like in general. If you are interested to create trending on wordpress blog without using the help of plugins, can directly follow some steps below.

Tips on Creating Trending in WordPress Without Plugins

Creating Trending in WordPress Without Plugins


1. Create a script for Function first as below and place in fungtion.php wordpress template you use, script below is used to cut title:
/*----------------------------------------*/
/*  Short Post Title
/*----------------------------------------*/
function mts_short_title($after = '', $length){
    $mytitle = get_the_title();
    if ( strlen($mytitle) > $length ){
        $mytitle = substr($mytitle,0,$length);
        echo $mytitle . $after;
    }
    else { echo $mytitle; }
}

2. After that add the script below in the header I put the code below under the body if the theme twenty fourteen, if in my template I put it in header.php
<div class="trending-articles">
                <ul>

                    <li class="firstlink"><?php _e('Trending','nama_template_anda'); ?>:</li>
                    <?php $i = 1; $my_query = new wp_query( 'cat='.'&posts_per_page=4&ignore_sticky_posts=1' ); ?>
                    <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
                        <li class="trending <?php if($i % 4 == 0){echo 'last';} ?>">
                            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php mts_short_title('...', 24); ?></a>
                        </li>
                    <?php $i++; endwhile; endif;?>
                </ul>
            </div>

3. To beautify the display add the css code below or you add your own CSS code according to your own design for your template.
.trending-articles{background:#2a2a2a;border-bottom:1px solid #000;float:left;width:100%;position:relative;z-index:100;}
.trending-articles ul{list-style:none;}
.trending-articles li{border-right:1px solid #7D7D7D;color:#fff;float:left;font-size:12px;font-weight:400;line-height:1.2em;margin:10px 0 9px;padding:0 13px;text-transform:none;}
.trending-articles li.firstlink{border:none;padding-left:20px;}
.trending-articles li.last{border:none;}
.trending-articles li a{color:#00c0ad;display:block;}
.trending-articles li a:hover{color:#fff;}

4. Done, and see the results

So this article I have shared about how to Creating Trending in WordPress Without Plugins, hopefully with this short enough article, can be useful and good luck.

1 comment for "Tips on Creating Trending in WordPress Without Plugins"

Provide comments relevant to the posted articles and provide critiques and suggestions for the progress of the blog