Welcome to PressWork!

Want to ask a question or join the discussion? Great! Join now.

In this Discussion

Related Posts Without a Plugin
  • I discovered this post that puts related posts on your blog without using a plugin. It's built around the Genesis theme, but I'd like to use it with PW. I made the appropriate changes to both my custom-actions.php and custom.css as called out in the post, but it didn't work.

    I'm wondering if there are specific changes I need to make in order for it to work on PW.
  • This is the hook you have to use for the code. The related posts will appear at the end of your single posts.
    add_action('pw_single_post_bottom','related_posts');

    .
    Post edited by cestbibi at 2012-02-14 06:41:27
    image PressWork Support Moderator
  • I made the change you suggested, but it's still not showing up on my site.

    Here is what I have in the custom-actions.php file
    <?php add_theme_support( 'post-thumbnails' );
    add_image_size( 'related-posts', 100, 100, true );
     
    function related_posts() {
    if ( is_single() ) {
    $orig_post = $post;
    global $post;
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
    $tag_ids = array();
    foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    $args=array(
    'tag__in' => $tag_ids,
    'post__not_in' => array($post->ID),
    'posts_per_page'=>5,
    'caller_get_posts'=>1,
    'orderby'=>'rand'
    );
    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
    echo '<div id="related_posts" class="clear"><h3>Read them too</h3><ul>';
    while( $my_query->have_posts() ) {
    $my_query->the_post(); ?>
    <li>
    <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
    <?php the_post_thumbnail( 'related-posts' ); ?>
    </a>
    <div class="related_content">
    <a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </div>
    </li>
    <? }
    echo '</ul></div>';
    } }
    $post = $orig_post;
    wp_reset_query(); ?>
     
    <?php } else { } }
     
    add_action('pw_single_post_bottom','related_posts');


    And here is what I have in the custom.css
    .custom #related_posts ul {
    margin: 0;
    overflow: hidden;
    padding: 5px 0;
    }
     
    .custom #related_posts li {
    float: left;
    list-style: none;
    margin: 0 0 0 20px;
    }
     
    .custom #related_posts li:first-child {
    margin-left: 3px;
    padding-left: 8px;
    }
     
    .custom #related_posts li a {
    border-bottom: medium none;
    display: block;
    font-size: 13px;
    line-height: 16px;
    text-align: left;
    text-decoration: none;
    width: 111px;
    }
     
    .custom #related_posts li a:hover {
    text-decoration:underline;
    }
     
    .custom #related_posts li a img {
    background: none repeat scroll 0 0 #EEEEEE;
    border: 1px solid #E1E1E0;
    height: 100px;
    padding: 4px;
    }
     
    .custom #related_posts li a img:hover {
    background: #DDD;
    border: 1px solid #CCC;
    }
     
    .custom #related_posts {
    height: 270px;
    }


    Any suggestions?
  • The php code you just posted works in my test site, I think the problem is the css try no to load the css part and you see it works.
    image PressWork Support Moderator
  • I did as you suggested, but still no luck.

    I deleted the information in the css and I don't see anything at the end of my posts. Any other ideas?
  • Can you provide a link to your site ?
    image PressWork Support Moderator
  • Mmm, I don't see any obvious error, again your same code is working in my PressWork test default install. Did you try to de-activate all your plugins ?
    image PressWork Support Moderator
  • No I have not tried that yet. I'll try that and see what happens.
  • I tried turning off all of the plugins with no luck. I even re-copied the code and added the "add_action('pw_single_post_bottom','related_posts');" at the end and replaced the one for the Thesis theme that the original post had up there. I also removed all of the CSS code I listed above. All with no luck. Nothing shows up at all: no text, not titles, etc.

    Any other suggestions?