Forums

Sections (12 posts)

  1. bestcssdesigns
    Member
    Posted 3 years ago #

    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; ?>
  2. stvwlf
    Member
    Posted 3 years ago #

    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

  3. bestcssdesigns
    Member
    Posted 3 years ago #

    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?

  4. stvwlf
    Member
    Posted 3 years ago #

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

  5. stvwlf
    Member
    Posted 3 years ago #

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

  6. bestcssdesigns
    Member
    Posted 3 years ago #

    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

  7. bestcssdesigns
    Member
    Posted 3 years ago #

    Just a lil more help please. I am not very good with PHP. :(

  8. bestcssdesigns
    Member
    Posted 3 years ago #

    Please help...

  9. t31os
    Member
    Posted 3 years ago #

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

  10. bestcssdesigns
    Member
    Posted 3 years ago #

    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.

  11. t31os
    Member
    Posted 3 years ago #

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

  12. bestcssdesigns
    Member
    Posted 3 years ago #

    Yes. Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.