• Hello,

    I just want to create a php file which includes the following code:

    <?php while (have_posts()) : the_post(); ?>
    
        <h3 id="post-<?php the_ID(); ?>">
          <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        </h3>
    
    <?php endwhile; ?>

    But I just want to show the content of one of my categories (Category 13). The term
    <h3 id="post-13; ?>">
    does not work. What do i have to change that just the entries of this category are shown? Is this possible?

    Thanks,
    Karin

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter karin24

    (@karin24)

    Thanks GamerZ for your post but all I tried does not work. I am using this code:

    <table border="0">
      <td>
    
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
        <?php query_posts('cat=13'); ?>
    
        <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
        <?php endif; ?>
    
      </td>
    </table>

    It should show me all content (headlines with possibility to click on it) of category 13.

    Any suggestions? Thanks, Karin

    Put that initial code of yours

    <?php while (have_posts()) : the_post(); ?>
    
        <h3 id="post-<?php the_ID(); ?>">
          <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        </h3>
    
    <?php endwhile; ?>

    in a file called category-13.php and when you click on the name/link of cat 13 WP will know to show only posts from that category.
    More: Category_Templates
    (actually, clicking on any category name should bring up only posts from that category – doesn’t that work for you?)

    Thread Starter karin24

    (@karin24)

    Thanks moshu.

    For some reasons this will not work. I dont want to create a file called category-13.php because everything is working fine within wordpress and i dont want to have different styles within my categorys.

    But I want to create a “plugin” which I can use on other static HTML pages. For example:
    I have a normal HTML page about fire in forrests. Then I want to include a box
    (<? include (“https://[mywebpage]/directoryofwordpress/fire.php&#8221;); ?>)
    with all my blog entries about the topic fire (category=13). So within this fire.php file all blog entries should be shown.

    Possible?

    That will never work on a “normal” html file. You cannot use a PHP include command in a html file.

    Thread Starter karin24

    (@karin24)

    That was a missunderstanding. I just wanted to say that the “normal HTML page” is NOT a database. Of course it is a php-page, but it is not located in the wp-folder. So I have to use the php-include-tag.

    Sorry ??

    I still wouldn’t use any includes…
    Just take that your non-WP php file, whatever.php – and on the top add this, before anything else:

    <?php
    require('./path-to-your-blog/wp-blog-header.php');
    ?>

    Then, where you want the list of posts from cat 13, put in this:

    <?php query_posts('category_name=fire'); ?>
    <?php while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
            <ul>
               <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
            </ul>
      </div>
    Thread Starter karin24

    (@karin24)

    I am sorry Moshu that I am too stupid to do it ?? Maybe because i am a woman, hihihi!!!

    I am currently using this code within my non-WP-file:

    <?php
    require('https://www.[domain]/database/wp-blog-header.php');
    ?>
    
    <?php query_posts('cat=23'); ?>
    <?php while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
            <ul>
               <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
            </ul>
      </div>

    But then I receive an errormessage “Parse error: syntax error, unexpected $end in “

    Why does it not work???? I am getting crazy ??

    try this code:

    <?php query_posts('cat=13'); ?>
    <?php while (have_posts()) : the_post(); ?>
    
        <h3 id="post-<?php the_ID(); ?>">
          <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        </h3>
        <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
        <?php endif; ?>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Showing just one category WITHOUT using the cat-ID’ is closed to new replies.