• Resolved newbiethis

    (@newbiethis)


    Hi all,

    I’m trying to start my blog, but am customising it and wondering how to achieve this – apologies for the bad description. I’m familiar with CSS but not PHP, hence the question.

    I want to have my blog home page have only the three latest posts from the 3 categories i specify (which will be updated every 2/3 days each). Only a portion of the post will be shown

    When I click on one of the posts, it’ll take the user to all the posts from that category, listed as reverse-chronologically as most blogs do. Once again, it’ll show most/all of the post.

    When a post on this 2nd-tier is clicked on, it takes you to the single-post view, where you can add comments etc as usual.

    So essentially, I think I’m adding a layer, but I want to showcase the different categories.

    Generally speaking, how would I go about achieving this?

    What php pages do I have to make changes to?

    Obviously the style.css page would also need to be changed.

    Any help would be appreciated, I just want to clarify the task before me.

    Cheers,

    J

Viewing 7 replies - 1 through 7 (of 7 total)
  • MichaelH

    (@michaelh)

    Only a portion of the post will be shown….Once again, it’ll show most/all of the post.

    You will need to read up on using template tag, the_content() or the_excerpt(), in your theme’s Templates. Also review the Excerpt article and the first four questions here. You will also want to have a basic understanding of the WordPress Template Hierarchy to know what Templates are used to render posts.

    I want to have my blog home page have only the three latest posts from the 3 categories i specify

    This will print categories and posts
    <?php
    //for categories 42,6,8, show 3 posts
    $cat_args=array(
      'include' => '42,6,8',
      'orderby' => 'name',
      'order' => 'ASC'
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => 3,
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
    ?>

    When I click on one of the posts, it’ll take the user to all the posts from that category, listed as reverse-chronologically as most blogs do. Once again, it’ll show most/all of the post.

    When a post on this 2nd-tier is clicked on, it takes you to the single-post view, where you can add comments etc as usual.

    The way WordPress works is “When I click on one of the Categories displayed with each post, it’ll take the user to all the posts from that category.” If you click on a post title, that will take you to the single post view.

    Obviously the style.css page would also need to be changed.

    Not necessarily so…

    Thread Starter newbiethis

    (@newbiethis)

    Thanks Michael, I appreciate your reply…

    I’ll learn up on this and see how I go!

    Cheers,

    J

    Thread Starter newbiethis

    (@newbiethis)

    Hi Michael,

    For the second answer you kindly provided, with the code, where do I put it? functions.php? or index.php?

    Sorry for the lame question…

    J

    MichaelH

    (@michaelh)

    According to Template Hierarchy I would put that in your index.php if you are doing displaying those posts on your ‘homepage’.

    To put that in functions.php would requiring making that code into a function and then invoking that function from index.php.

    Thread Starter newbiethis

    (@newbiethis)

    Thanks Michael!

    I’ve managed to achieve most of what I’ve asked so far, thanks to the assistance you have provided ??

    I’ll work on this now and see how I go – once again, thanks!

    Thanks Michael for sharing this script. I’ve been trying to mod it so the posts that are queried are displayed randomly. Nothing I’ve tried seems to work. I’ve tried using the orderby set to rand and it doesn’t work. Anyone have any ideas?

    Thanks Michael for the code. Just another question, how do I implement 'feed '=> 'RSS' to the code?

    On the
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> Feed Icon Here</p> ';

    I want to have the Feed Icon by each category

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How put latest post from each category on homepage’ is closed to new replies.