This topic contains 16 replies, has 2 voices, and was last updated by  Joel 3 years, 8 months ago.

  • Creator
    Topic
  • #1048

    Joel
    Participant

    Hi Dominykas

    I’m using Woothemes Canvas which gives me the option of putting a widget as page content so I wish to have a page that shows the top rated posts.

    I used the widget and it works fine but it only shows the titles. I’d like to add in Thumbnail, excerpt and view more link too so that it looks a bit like an archive page.

    Could you tell me which file to edit please?

    Thanks very much.

    Joel

  • Author
    Posts
  • #1050

    Dominykas
    Keymaster

    Hi Joel,

    I don’t think you need to edit any file, but create a new function/shortcode for the top rated posts. I’ll help you to create it. Do you have any request for layout? Do you need a list of posts or grid?

    Thumbnail – do you mean the featured image? Thumbnail/exceprt/view more link should be from rated posts?

    Thanks!

  • #1052

    Joel
    Participant

    Hi Dominykas

    That’s great thank you :-)

    Yes I mean featured image and I would like a list. I wish to make a Top rated posts page where the posts sit in a list and it looks the same as a normal post archive page. So it would like:

    http://devree.carciofino.co.uk/

    I would want the code for each post summary to be similar to this:

    “><?php the_post_thumbnail(‘blog’); ?>
    <h2 class=”title entry-title”>“><?php the_title() ?></h2>
    <?php the_excerpt() ?>
    <span class=”viewmore”>“>VIEW MORE ></span>
    <div class=”clear”></div>
    <hr />

    I guess all sitting inside one div would be good so that I can apply any distinct additional styling if needed.

    Does that answer your question so that you can help me?

    Thanks very much for the great support.

    Joel

  • #1053

    Joel
    Participant

    It stripped out the first part of my code!

    <!—
    “><?php the_post_thumbnail(‘blog’); ?>
    <h2 class=”title entry-title”>“><?php the_title() ?></h2>
    <?php the_excerpt() ?>
    <span class=”viewmore”>“>VIEW MORE ></span>
    <div class=”clear”></div>
    <hr />
    –>

    trying again

  • #1054

    Joel
    Participant

    it’s missing an a href to the permalink at the beginning so that the post thumbnail links to the post…

  • #1056

    Dominykas
    Keymaster

    Hi Joel,

    Thanks for a very detailed explanation of the problem!

    I understand now what you need. It’ll take some time for me to create such shortcode because I need to do some testing, so I’ll get back to you tomorrow.

  • #1057

    Dominykas
    Keymaster

    Hi Joel,

    I wrote a shortcode and pasted here: http://pastebin.com/yY2yht7M Simply, add it to your theme’s functions.php file, then use [elm_custom_top_rated] shortcode and it’ll display a nice list of top rated posts including featured image, excerpt and view more link. If you want to edit the layout, then take a look at 57-69 lines.

    Hope this helps!

  • #1058

    Joel
    Participant

    Thank you very much Dominykas.
    This looks great.
    Will implement and let you know if I have any problems.

    Thanks

    Joel

  • #1061

    Joel
    Participant

    Hi Dominykas

    This is almost perfect – thank you.

    The posts are pulling in the full post content rather than just the excerpt.

    Top Rated Products

    I assume it’s this line that needs editing:

    $html .= apply_filters(‘the_excerpt’, get_post_field( ‘post_content’, $posts[$key][‘id’] ) );

    I’ve tried playing about with it but can’t quite seem to get it right.

    If you can easily see what the change I should make is that would be very helpful.

    Thank you

    Joel

  • #1063

    Dominykas
    Keymaster

    Hi Joel!

    You are talking about the right line. I think you need a function to truncate full post content.

    Firstly, add this function:

    function ttruncat($text,$numb) {
    if (strlen($text) > $numb) {
    $text = substr($text, 0, $numb);
    $text = substr($text,0,strrpos($text,” “));
    $etc = ” …”;
    $text = $text.$etc;
    }
    return $text;
    }

    to your theme’s functions.php file.

    Secondly, change this line:

    $html .= apply_filters(‘the_excerpt’, get_post_field( ‘post_content’, $posts[$key][‘id’] ) );

    to:

    $html .= ttruncat( get_post_field( ‘post_content’, $posts[$key][‘id’] ), 150 );

    Here:

    get_post_field( ‘post_content’, $posts[$key][‘id’] ) – is the text (full post content)
    150 – the number of characters that you want to output.

    Hope this helps.

    Please let me know if you have any more questions.

  • #1068

    Joel
    Participant

    Hi Dominykas

    Thank you very much for this. I got it all working and it does excatly what we want.

    Now the client has changed the design so I have to do it all again but I think I can manage on my own using what you provided – thank you very much.

    I have another request which relates to my first post so will respond there – thank you again for all of your help with this.

    Joel

  • #1070

    Dominykas
    Keymaster

    Hi Joel,

    No problems! :) I’m glad to hear that you got everything working.

  • #1071

    Joel
    Participant

    Hi Dominykas

    I got my new layout sorted as a grid and all is working well.

    Just one last question for you please on this – how do I limit the output to only show 10 posts ?

    Thank you very much

    Joel

  • #1072

    Dominykas
    Keymaster

    Hi Joel,

    Great! You need to add $atts[‘limit’] = 10; before global $wpdb; See example: http://pastebin.com/Kzu3TY2V

    Please let me know if you have any more questions.

  • #1073

    Joel
    Participant

    Thank you :-)

    Sorry can I just double check please – before or after as in pastebin?

    I tried both and doesn’t seem to work – could I be missing a bracket or something?

    Thank you again.

    Joel

  • #1074

    Dominykas
    Keymaster

    Ah, I found a SQL error. I updated the function and it should work now. Please replace your function with code from this pastebin: http://pastebin.com/ZFDARVje

    Please let me know how it goes.

  • #1075

    Joel
    Participant

    Perfect – thank you :-)

The topic ‘[Solved] Adding content to the widget’ is closed to new replies.