• 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?

Viewing 12 replies - 1 through 12 (of 12 total)
  • You mean you only want to display posts from category 4? Directly from the Codex page:
    <?php query_posts('cat=4'); ?>

    Thread Starter dudskie

    (@dudskie)

    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?

    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; ?>
    Thread Starter dudskie

    (@dudskie)

    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 https://www.mydomain.com/blogs. And I want to display this information to https://www.mydomain.com only. Is there any code that I have to call to the blogs folder? Thanks in advance.

    Thread Starter dudskie

    (@dudskie)

    Please help. Thanks.

    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');
    ?>

    https://www.ads-software.com/support/topic/127103?replies=15#post-592826

    Thread Starter dudskie

    (@dudskie)

    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; ?>
    Thread Starter dudskie

    (@dudskie)

    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

    Thread Starter dudskie

    (@dudskie)

    That’s the last problem ??

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

    Thread Starter dudskie

    (@dudskie)

    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. ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Create a query’ is closed to new replies.