• In WordPress, I am trying to have content from only a certain category be shown in a certain section of the website.

    I am using this code in a certain section of my website. If i want content from a specified category to appear in this area, what do I have to do?

    <?php if ($aOptions['column2-id'] != '') { query_posts('p=' . $aOptions['column2-id']); } ?>
    <?php while (have_posts()) : the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
    <?php the_content(''); ?>
    <?php endwhile; ?>
Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi

    Your code appears to be pulling in a post or posts ID, not a category.

    The simple syntax for what you want is
    query_posts('cat=4');

    to use the contents of PHP variables like this

    $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC';
    query_posts($query)

    If you haven’t seen the query_posts codex page it is here
    http://codex.wordpress.org/Template_Tags/query_posts

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    That script that i posted above came with the template. But how can I get is to pull from a category instead of using Post ID?

    I just gave you the code to do that (above)

    Categories have their own category ID codes – that is what is being specified in the query_posts code I posted

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    Sorry. I am very noob with PHP. Can you please tell me exactly what to put in the place of

    <?php if ($aOptions['column2-id'] != '') { query_posts('p=' . $aOptions['column2-id']); } ?>
    <?php while (have_posts()) : the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
    <?php the_content(''); ?>
    <?php endwhile; ?>

    Because the code that you posted seems like it needs to be in some brackets or something. It didn’t work. :S

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    Just a lil more help please. I am not very good with PHP. πŸ™

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    Please help…

    <?php if ($aOptions['column2-id'] != '') { query_posts('cat=4&p=' . $aOptions['column2-id']); } ?>
    <?php while (have_posts()) : the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
    <?php the_content(''); ?>
    <?php endwhile; ?>

    See this part i just added…

    cat=4

    Adjust the 4 to the ID of your chosen category…

    You can tell which ID your category has by viewing it on your website, the link in the browser should be something like…

    http://www.yoursite.com/index.php?cat=1
    or
    http://www.yoursite.com/index.php?cat=2
    or
    http://www.yoursite.com/index.php?cat=3

    and so on…

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    Hi,

    I entered in the following code for the sections at http://www.mountoliveadventist.org

    <?php if ($aOptions['column2-id'] != '') { query_posts('cat=3&p=' . $aOptions['column2-id']); } ?>
    <?php while (have_posts()) : the_post(); ?>
    <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
    <?php the_content(''); ?>
    <?php endwhile; ?>

    However, nothing is showing. I even got the plugin that reviews the ID’s for each category. And I know I chose the right category because if you go to http://mountoliveadventist.org/?cat=3 it will show the content.

    Please help. Thanks.

    For testing sake, does it work if you change this line..

    <?php if ($aOptions['column2-id'] != '') { query_posts('cat=3&p=' . $aOptions['column2-id']); } ?>

    To..

    <?php query_posts('cat=3');?>

    Thread Starter bestcssdesigns

    (@bestcssdesigns)

    Yes. Thanks so much!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Sections’ is closed to new replies.