Forums » Fixing WordPress » how to connect post title with its content on a page

  • Hej, i am not really good in wordpress, so i need some help I am trying to create list of projects(post title) in the side bar i want content of each project to be shown when title link is clicked. anyone have an idea how to do it?

    code for title:

    <div class="list_of_projects">
    
    <ul>
    <li>
         <?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=-1");
      if ($posts) {
        foreach ($posts as $post):
          setup_postdata($post); ?>
          <div class="project_title">
          <a href=""><h2 class="tytul"><?php the_title(); ?></h2></a>
                    <p class="border_artykul"></p>
                    </div>
    			<?php wp_reset_query(); ?>
        <?php endforeach;
      }
    }
    ?>
    </li>
    </ul>
    </div>
    <!-- end list of projects-->
    
    code for content:
    
     <?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=1");
      if ($posts) {
        foreach ($posts as $post):
          setup_postdata($post); ?>           
    
    <ul>
    <li><?php the_content(); ?></li>
    </ul>
    			<?php wp_reset_query(); ?>
        <?php endforeach;
      }
    }
    ?>
  • The topic ‘how to connect post title with its content on a page’ is closed to new replies.