WordPress.org

Support

Support » Themes and Templates » [Resolved] showing pages within posts

[Resolved] showing pages within posts

  • i am putting a page list based on category onto posts, different page lists on different posts, which the code below does:


    <? if (is_page('7')) { ?>
    <? $posts = get_posts('order=DESC&category=1'); foreach ($posts as $post): ?>
    <? the_title(); ?>
    <? endforeach; ?>

    this however ONLY works if there are pages in that category, if there’s no there’s an error. how do i make it conditional to there being pages within the category? so if there are pages (one or more) then it shows them, if there’s no pages posted in the category it posts nothing?

    any help would be appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can’t associate pages with categories, only posts…

    sorry, that’s what i meant. it grabs posts in those categories from the get_posts. now i want it to only happen if there are posts in those categories. right now that get_posts returns an error if there are no posts in the category.

    You might try changing

    <? if (is_page('7')) { ?>

    to

    <? if (is_page('7') && have_posts()) { ?>

    i still get a:

    Warning: Invalid argument supplied for foreach()

    i got it now:

    if i add an IF before the for statement.

    <? $posts = get_posts(‘order=DESC&category=1’); if ($posts) : foreach ($posts as $post): ?>

    thanks for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] showing pages within posts’ is closed to new replies.
Skip to toolbar