13 replies
I have a blog with 3 categories, I want to only show my main category's posts on the front page. Currently front page is showing most recent posts. Is it possible? Thanks
#question #wordpress
  • Profile picture of the author The Pension Guy
    Yes, it is possible, although - depending on your theme - it would involve changing the Loop in the index.php file of your theme: see the examples for excluding categories on the page in the Codex.
    Signature

    {{ DiscussionBoard.errors[1018931].message }}
  • Profile picture of the author WARRIOR_USA
    I don't know coding at all so do not want to mess with index file. Is there any other solution to that?

    Thanks
    {{ DiscussionBoard.errors[1018949].message }}
    • Profile picture of the author The Pension Guy
      Originally Posted by WARRIOR_USA View Post

      I don't know coding at all
      Then you will have to hire somebody to do it for you... or ask a friend.


      @meldave - that's not what the OP asked and your answer is not helpful because it is irrelevant...
      Signature

      {{ DiscussionBoard.errors[1018959].message }}
  • Profile picture of the author meldave
    You could also use their sticky plugin which will put your main post in the first position.
    {{ DiscussionBoard.errors[1018951].message }}
  • Profile picture of the author WARRIOR_USA
    I want to show posts from my main category on the front page only. Would sticky plugin do that?

    Thanks
    {{ DiscussionBoard.errors[1018960].message }}
  • Profile picture of the author The Pension Guy
    No, it wouldn't. See my post above.
    Signature

    {{ DiscussionBoard.errors[1018962].message }}
  • Profile picture of the author WARRIOR_USA
    Would you be able to help if I pm you my source code? Thanks
    {{ DiscussionBoard.errors[1018967].message }}
  • Profile picture of the author The Pension Guy
    Yes, sure.
    Just need to know (i.e. let me know in the PM) the category ID that you want to be displayed on the main page.
    Signature

    {{ DiscussionBoard.errors[1018979].message }}
  • Profile picture of the author WARRIOR_USA
    Is category ID same as the category slug or category name?
    {{ DiscussionBoard.errors[1019080].message }}
  • Profile picture of the author martin2
    go to categories section inside wp-admin, click on wanted category, you will see on browser addressbar CAT_ID, remember it's your category id.

    Now go to your index.php, you will need to modify wordpress API

    here is example on how you can show selected categories on sidebar :

    <?php if ( have_posts() ) : ?>

    // take a look at line below, &cat=3 , change 3 to your category id.

    <?php $my_query = new WP_Query('showposts=1&cat=3');

    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>


    <?php
    $id =$post->ID;
    $the_content =
    $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id ");
    $pattern = '!<embed.*?src="(.*?)"!';

    preg_match_all($pattern, $the_content, $matches);
    $obj_src = $matches['1'][0];
    ?>


    <?php if($obj_src != '')

    {

    echo '<b>Latest Video</b><br><br><object width="160" height="120">
    <param name="movie" value="'.$obj_src.'"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="'.$obj_src.'" type="application/x-shockwave-flash"
    allowscriptaccess="always" allowfullscreen="true" width="160" height="120">
    </embed>
    </object><br><br>';

    }


    ?>

    <?php endwhile; ?>

    <?php endif; ?>

    You can do the same on your index.php, check oyt this line of code
    $my_query = new WP_Query('showposts=1&cat=3');


    Good luck.

    If you need more API modifications , PM me , I will not charge alot.
    {{ DiscussionBoard.errors[1019112].message }}
  • Profile picture of the author WARRIOR_USA
    Hi Martin, I don't want to show the category on the side bar. I want to show only the posts from my main category on the front page. Currently, blog is showing all the categories on the front page.

    Thanks
    {{ DiscussionBoard.errors[1019188].message }}
  • Profile picture of the author John Dufresne
    Hi WARIOR_USA,
    You could try going to wordpress and searching the plugins.
    I know what your talking about, but messing with the index.php file could be a no no if you don't have a backup of the file.
    There is hundreds, if not thousands of plugins floating around, I'm sure someone has one somewhere.
    Signature
    {{ DiscussionBoard.errors[1019272].message }}
  • Profile picture of the author The Pension Guy
    I completely forgot about this plugin:
    WordPress › Advanced Category Excluder WordPress Plugins
    Signature

    {{ DiscussionBoard.errors[1019342].message }}

Trending Topics