• For the Home page I have created wordpress page and made it as index page (not using index.php). I want to display recent 3 posts in that page. The following code works in side bar.php but not in home page wordpress page. I installed execphp.

    <?php
    if (is_page()) {
      $cat=get_cat_ID($post->post_title); //use page title to get a category ID
      $posts = get_posts ("cat=$cat&showposts=3");
      if ($posts) {
        foreach ($posts as $post):
          setup_postdata($post); ?>
          <div class="postlists">
             <div class="posttitle">
                  <a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    	     </div>
    	     <?php the_excerpt() ?>
          </div>
        <?php endforeach;
      }
    }
    ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.]

    Any help?

Viewing 1 replies (of 1 total)
  • Thread Starter PNParamasivan

    (@pnparamasivan)

    I solved it with echo as below:

    <?php if (is_page()) {
    $cat=get_cat_ID($post->post_title); //use page title to get a category ID
    $posts = get_posts ("cat=$cat&showposts=3");
    if ($posts) {
    foreach ($posts as $post):
    setup_postdata($post); ?>
    <div class="postlists"><div class="posttitle">
    <a href="<?php echo get_permalink($post->ID); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo $post->post_title; ?></a>
    </div>
    <?php the_excerpt() ?></div>
    <?php endforeach;
    }
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Admin posts in Home page’ is closed to new replies.