Forums

Create a query (13 posts)

  1. dudskie
    Member
    Posted 2 years ago #

    Hi i want to create a query that displays all the contents of cat_ID whose value is 4. I mean the wp_posts table whose cat_ID in the table wp_categories is 4. How to do that?

  2. tsguitar
    Member
    Posted 2 years ago #

    You mean you only want to display posts from category 4? Directly from the Codex page:
    <?php query_posts('cat=4'); ?>

  3. dudskie
    Member
    Posted 2 years ago #

    Yes, I want to create a code that will display all the value 4 of cat_id in the wp_categories table and I want to post only the TITLE and DATE only on my homepage. How to do that?

  4. tsguitar
    Member
    Posted 2 years ago #

    So, on your home page, you only want to list content from category 4? Put this in place of your current Loop:

    <?php query_posts('cat=4');
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="permalink to <?php the_title(); ?>"><?php the_title(); ?></a></p>
    <p><?php the_time('d, M, Y') ?></p>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  5. dudskie
    Member
    Posted 2 years ago #

    Thank you very much. It is a great help. One thing question is. Is this should work in my website homepage? Actually my blogs are located in http://www.mydomain.com/blogs. And I want to display this information to http://www.mydomain.com only. Is there any code that I have to call to the blogs folder? Thanks in advance.

  6. dudskie
    Member
    Posted 2 years ago #

    Please help. Thanks.

  7. tsguitar
    Member
    Posted 2 years ago #

    First off, does that query do what you need it to?

    Secondly, you can include WordPress content on any page that you add the following to the top of:

    <?php
    /* Short and sweet */
    require('path/to/wp-blog-header.php');
    ?>

    http://wordpress.org/support/topic/127103?replies=15#post-592826

  8. dudskie
    Member
    Posted 2 years ago #

    One last question, I am not sure where is that current Loop located? Is that a file you mentioned (wp-blog-header.php)? I am not sure where to put the code below. Thanks and sorry, this is my first to used WordPress.

    <?php query_posts('cat=4');
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="permalink to <?php the_title(); ?>"><?php the_title(); ?></a></p>
    <p><?php the_time('d, M, Y') ?></p>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  9. tsguitar
    Member
    Posted 2 years ago #

  10. dudskie
    Member
    Posted 2 years ago #

    Thanks tsguitar.. It really works... I learned a lot of this template tags.

    Now, I have another question. This is in connection with the problem above. The template tags above shows I have 25 titles with dates. Now, I want to display only 4 titles with dates then there is an option that click here for the next four titles with dates. How will I do that?

    This should fixed my problem.

    Thanks

  11. dudskie
    Member
    Posted 2 years ago #

    That's the last problem :)

  12. Sivar
    Member
    Posted 2 years ago #

    Modify query_posts('cat=4'); to query_posts('cat=4&showposts=4');. See query_posts() in the codex for more options.

  13. dudskie
    Member
    Posted 2 years ago #

    I mean the second four will show if I click Next, then when I click Previous it will go to the previous post. Sorry for misunderstanding. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.