• Resolved adamgay

    (@adamgay)


    This is probably just some little mistake, or something I’m missing, but the docs don’t seem to have any reference for what I’m trying to do.

    I’ve got a site for a client, and he needs to use wordpress for updating posts on cars he’s sold, and cars he has for sale. So what I wanted to do was make a page that’s “For Sale” and a page that’s “Sold”. Then, each page would display only posts from a specific category (like ‘sold’ and ‘forsale’). Not sure why I can’t get it to show. Here’s the code within the “Sold” page.

    Call at beginning:
    <?php define('WP_USE_THEMES', false); get_header('/var/www/jettvettes.com/public/blog/wp-blog-header.php') query_posts('category_name=vettessold'); ?>

    Code for the posts (including The Loop):

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<div id="welcome" class="post">
    		<h2 class="title"><?php the_title(); ?></h2>
    		<h3 class="date"><?php the_date(); ?> Posted by <?php the_author(); ?></h3>
    		<div class="story">
    			<?php the_content(); ?>
    		</div>
    	</div>
    <?php endforeach; else: ?>
    <p><?php _e('Sorry, nothing to show you for now, Check back later!'); ?></p>
    <?php endif; ?>

    any ideas? Like I said, I’m probably just missing something, or have something entered wrong. I’m not too familiar with WordPress.

Viewing 14 replies - 1 through 14 (of 14 total)
  • esmi

    (@esmi)

    Thread Starter adamgay

    (@adamgay)

    According to that page, I needed to change the get_header() function to the require() function. Even after I did that, it’s not working.

    I’ve even tried to get the page to just grab the newest posts, and it still doesn’t grab anything. I’ve got another site set-up almost identical to this, and it works flawlessly, what am I doing wrong?

    EDIT:
    Here’s the updated code:

    <?php require('/var/www/jettvettes.com/public/blog/wp-blog-header.php'); query_posts('category_name=vettessold';) ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div id="welcome" class="post">
    		<h2 class="title"><?php the_title(); ?></h2>
    		<h3 class="date"><?php the_date(); ?> Posted by <?php the_author(); ?></h3>
    		<div class="story">
    			<?php the_content(); ?>
    		</div>
    	</div>
    <?php endwhile; else: ?>
    <?php _e('Sorry, nothing here for you right now. Check beck later!'); ?>
    <?php endif; ?>

    Here’s the site that’s working

    Here’s the page I’m trying to fix

    esmi

    (@esmi)

    Try reading the page again. You need to use get_posts or query_posts.

    Thread Starter adamgay

    (@adamgay)

    I’m confused…

    query_posts() is being used in my code. I’ve tried it at the top, and just before The Loop. It’s in my code above, and it was in the original code I posted.

    According to the WordPress Docs, $category_name is a valid variable for the query_posts() function, so it can’t be the way it’s being used, unless it needs to be in a different location. If that is the case, I need to know where. There’s nothing specifying that’s the problem, though.

    I’ve also tried using get_posts(), but my results are the same.

    freesouldesign

    (@freesouldesign)

    If the file wp-blog-header.php is located inside your template directory you don’t need to link to that way, you can just type

    <? php require('wp-blog-header.php'); ?>

    You can also do queries and display posts from a certain category in a Featured Category Box manner. Have the two categories’ posts listed side by side.

    You can also create a minimalistic version on the home page where you display only the post titles(car model I suggest) on top of each other and display the post thumbnail (car photo) above each column. Then on hovering a specific post title(car) you can change that photo. Here is how to do it. This is also suitable for the sidebar.

    Just suggestions to make your client happier ??

    Thread Starter adamgay

    (@adamgay)

    This isn’t a template. It’s something I put together, and the blog header is in a different directory. I had to put the full path in my other page to get it working, so I’m guessing it’s the same case here.

    As far as the design, and how things are displayed, the way I’m setting it up is how the client wants it. Unfortunately I can’t change his mind, he’s kinda stubborn.

    Thread Starter adamgay

    (@adamgay)

    Could it be a problem with something on my server, or with my database?

    I have it set up EXACTLY like the working site, yet it still will not display anything. WordPress by itself, is working properly, the back-end and front-end. I just can’t get anything to show up in my page.

    I’m especially getting a bit angry that it’s got the same code and set-up as my other site, and it won’t work.

    Are you certain the require statement is succeeding?

    If you’ve turned off error reporting you’re not see the failed message.

    Thread Starter adamgay

    (@adamgay)

    I’m not entirely sure if it is or not.

    How would I go about turning error reporting on for this particular situation?

    You could try via .htaccess

    php_flag display_errors on
    php_value error_reporting 8

    More information on error levels, denoted by the 8 in the above.
    https://us2.php.net/manual/en/errorfunc.constants.php

    Thread Starter adamgay

    (@adamgay)

    I’m not getting any errors. Just to be sure, I enabled error logging, but still no errors.

    I’m off to bed now, but i’ll leave you with a few small suggestiobs.

    Try the require with an incorrect path(something you know will fail), you’ll know if the error reporting is working.

    Try printing out some variables that would only be present if the require succeeded, look at the file if you need to, and remember you may need to globalise them first.

    Night.

    Thread Starter adamgay

    (@adamgay)

    Thanks a bunch. The require() function wasn’t working properly with the file as .html, but it was with it as .php. The other site is .html, so I’m not sure why it’s different here.

    Unless you’re telling the server to interpret html files as PHP that would happen yes.

    Happy to hear you resolved the issue in any case.. ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Problems displaying specific categories’ is closed to new replies.