Need help? Check out our Support site, then


Custom Title for Related Posts Shortcode

  1. Displaying a related posts through shortcode is very useful. But since I'm not familiar with programming, I can't customize it. Here's the code:
    <br /> // Related Posts<br /> function related_posts_shortcode( $atts ) {<br /> extract(shortcode_atts(array(<br /> 'limit' => '5',<br /> ), $atts));</p> <p>global $wpdb, $post, $table_prefix;</p> <p>if ($post->ID) {<br /> $retval = '</p> <ul>';</p> <p>// Get tags<br /> $tags = wp_get_post_tags($post->ID);<br /> $tagsarray = array();</p> <p>foreach ($tags as $tag) {<br /> $tagsarray[] = $tag->term_id;<br /> }<br /> $tagslist = implode(',', $tagsarray);<br /> // Do the query<br /> $q = "<br /> SELECT p.*, count(tr.object_id) as count<br /> FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p<br /> WHERE tt.taxonomy ='post_tag'<br /> AND tt.term_taxonomy_id = tr.term_taxonomy_id<br /> AND tr.object_id = p.ID<br /> AND tt.term_id IN ($tagslist)<br /> AND p.ID != $post->ID<br /> AND p.post_status = 'publish'<br /> AND p.post_date_gmt < NOW()<br /> GROUP BY tr.object_id<br /> ORDER BY count DESC, p.post_date_gmt DESC<br /> LIMIT $limit;";<br /> $related = $wpdb->get_results($q);</p> <p>if ( $related ) {<br /> foreach($related as $r) {<br /> $retval .= '</p> <li><a>ID).'">'.wptexturize($r->post_title).'</a></li> ';}<br /> }<br /> else {<br /> $retval .= ' <li>No related posts found</li> ';<br /> }<br /> $retval .= '</ul> ';<br /> return $retval;<br /> }<br /> return;<br /> }<br /> add_shortcode('related_posts', 'related_posts_shortcode');
    I didn't make that code; I just copy and paste it from a tutorial.

    Now, let's say I added a "[related_posts] on my content.
    Then, the 5 related posts displayed like this: (for example)
    1.
    2.
    3.
    4.
    5.

    Now what I want to do is this:
    (Add title like related posts)
    1.
    2.
    3.
    4.
    5.
    (add more texts here)

    Thanks.

    The blog I need help with is designrshub.com.

  2. The blog you specified at designrshub.com does not appear to be hosted at WordPress.com.

    This support forum is for blogs hosted at WordPress.com. If your question is about a self-hosted WordPress blog then you'll find help at the WordPress.org forums.

    If you don't understand the difference between WordPress.com and WordPress.org, you may find this information helpful.

    If you forgot to include a link to your blog, you can reply and include it below. It'll help people to answer your question.

    This is an automated message.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags