• Resolved goldmember

    (@goldmember)


    on this page (https://www.checkoutmywatch.com/wordpress/all-mens-watches/) i included the code below to take all the posts from category 23 (mens watches) and put them in the page. however it’s spitting out the error that you see on the page.

    please advise how to fix. thanks.

    <?php $recent = new WP_Query("cat=23&order=ASC"); while($recent->have_posts()) : $recent->the_post();?>
    <a href="<?php the_permalink() ?>">
    <?php the_title(); ?>
    </a>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <br />
Viewing 8 replies - 1 through 8 (of 8 total)
  • racer x

    (@racer-x-1)

    Try using query posts.

    If using the above method:

    <?php $recent = new WP_Query();
    $recent->query('cat=23&order=ASC'); ?>

    then the loop…

    All you need is though is query posts unless there will be multiple queries on this page.

    Thread Starter goldmember

    (@goldmember)

    well i have different pages where i want to list different sorts of posts so i’m not using the loop.

    but i tried putting that code into this page (https://www.checkoutmywatch.com/wordpress/all-mens-watches/), and i’m still getting an error.

    please advise. thanks.

    racer x

    (@racer-x-1)

    You are not seeing an “error”(as in, error reported by php). You would never see php code directly output to the browser window like that unless a start <?php or end ?> tag was omitted.

    Can you post exactly the code being used?

    Thread Starter goldmember

    (@goldmember)

    <?php $recent = new WP_Query();
    $recent->query('cat=23&order=ASC'); ?>
    <a href="<?php the_permalink() ?>">
    <?php the_title(); ?>
    </a>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <br />
    racer x

    (@racer-x-1)

    Are you putting this in the actual text area in the admin area by any chance?(Please don’t be offended by this question if not) It has converted the ‘ to html entities( #8216; ). All of the code is being output to the browser. That is not normal. That should have been parsed.

    You can’t put php in the post edit area if this is the case. I must be put in the page code like page.php, etc.

    Thread Starter goldmember

    (@goldmember)

    I’m putting the code in the content box, HTML tab, of my “All Mens Watches” page.

    racer x

    (@racer-x-1)

    Oh, I figured you might be. WP does not allow you to put php into those areas. HTML is allowed, but not php unless you use a plugin, but that is not how you want to do that.

    PHP is code that gets executed on the server side “before” you see the page. Then the PHP parser outputs(creates) dynamic html which makes up your page code.

    The code you are wanting to needs to be put into the page template file. This may be more advanced than what you want to do.

    Search “list posts by category” in plugins which will allow you to use shortcode or other means to do this.

    Thread Starter goldmember

    (@goldmember)

    got it. thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Error when including posts in page’ is closed to new replies.