WordPress.org

Ready to get started?Download WordPress

Forums

Conditional Statement in Post File?? (4 posts)

  1. Altstatten
    Member
    Posted 8 years ago #

    Here's what I'm trying to do. I think I know HOW, just need some help putting the code together.

    *******************************************
    (Writing a post.)
    If the post is assigned to CATEGORY X then post as usual.
    If same post is assigned to CATEGORY Y,...
    Then utilize the block of text below (as a "preamble" to the entire post)

    (text to be placed prior to the title, date, etc. of any post aqssigned to CATEGORY Y)
    "adfasd asd adsf dsa f asdf hg dfg gf hsdfg dfadsrethh sdfg jdf jkldsfsfjl iore emk lsfd klk;sdf"
    *********************************************

    I believe that's called a conditional tag and is to be placed within the loop. If someone could kindly put that into "words" that WP would understand, I'll just cut 'n paste that into the loop and be on my way! Thanks.

  2. moshu
    Member
    Posted 8 years ago #

    Define "Post File".
    I mean WHERE do you want that blah-blah to appear? On your index? On single post view? On monthly archives? On category archives? Don't be shy :) - Give as more details as you can.
    (not that I am a coder, but any helper will appreciate a detailed, precise description.

  3. Altstatten
    Member
    Posted 8 years ago #

    I think I'm just about there. I'm getting an error coder for line 68! I have to assume that the conditional tag I've placed in lines 10-14 will work but apparently there's some kind of conflict with line 68 and/or thereafter. Anyone able to see the problem?
    ***************************************
    <?php get_header(); ?>
    <?php get_sidebar(); ?>

    <div class="main-copy">
    <!-- Start Posts -->

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if (in_category('4')) : ?>{
    echo 'This article is reprinted with the express permission of the author. Additional bio and contact material about the author can be found at the end of the article. In addition, if you have sales tips or strategies articles you'd like to see published on this site we invite you to <A HREF="mailto:contact@salestipdigest.com">submit your articles</A> for review. Good selling!';
    } else {
    echo '';
    }

    <!-- ##### Main Copy ##### -->

    <div class="date-header"><?php the_time('F jS, Y') ?></div>

    <h1 style="border-top: none; padding-top: 0;" id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h1>
    <div class="post"><?php the_content('Read the rest of this entry »'); ?>
    Posted by <?php the_author() ?> in <?php the_category(', ') ?>
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit','',''); ?>
    </div><!-- post -->

    <?php link_pages('Pages: ', '', 'number'); ?>

    <p class="postmetadata alt">
    This entry was posted
    <?php /* This is commented, because it requires a little adjusting sometimes.
    You'll need to download this plugin, and follow the instructions:
    http://binarybonsai.com/archives/2004/08/17/time-since-plugin/ */
    /* $entry_datetime = abs(strtotime($post->post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */ ?>
    on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?>
    and is filed under <?php the_category(', ') ?>.
    You can follow any responses to this entry through the comments <?php comments_rss_link('RSS 2.0'); ?> feed.

    <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    // Both Comments and Pings are open ?>
    You can leave a response, or ">trackback from your own site.

    <?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    // Only Pings are Open ?>
    Responses are currently closed, but you can ">trackback from your own site.

    <?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    // Comments are open, Pings are not ?>
    You can skip to the end and leave a response. Pinging is currently not allowed.

    <?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    // Neither Comments, nor Pings are open ?>
    Both comments and pings are currently closed.

    <?php } edit_post_link('Edit this entry.','',''); ?>

    <!-- postmetadata alt -->

    <?php comments_template(); ?>

    <?php // comments_template(); ?>

    <?php endwhile; else: ?>

    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php endif; ?>

    <?php get_footer(); ?>

  4. Ajd777
    Member
    Posted 8 years ago #

    <?php if (in_category('4')) : ?>{
    This line here is the culprit I think. You never end this if.

    I think what you meant is to have this:
    <?php if (in_category('4')) : ?>{
    echo 'This article is reprinted with the express permission of the author. Additional bio and contact material about the author can be found at the end of the article. In addition, if you have sales tips or strategies articles you'd like to see published on this site we invite you to <A HREF="mailto:contact@salestipdigest.com">submit your articles</A> for review. Good selling!';
    } else {
    echo '';
    }

    Actually be this:
    <?php if (in_category('4')) {
    echo 'This article is reprinted with the express permission of the author. Additional bio and contact material about the author can be found at the end of the article. In addition, if you have sales tips or strategies articles you'd like to see published on this site we invite you to <A HREF="mailto:contact@salestipdigest.com">submit your articles</A> for review. Good selling!';
    } else {
    echo '';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic