Forums

if else with excerpts (16 posts)

  1. shinchook
    Member
    Posted 3 years ago #

    Ok so I on my page url = http://designsbyjot.com
    I finally got the coding correct so that the mini posts are showing the excerpt under the title. (I did this because if I have a pic in the post it will also write the parameters for the image instead of showing the image)

    Now I want to code an if else so that if there is not excerpt a message "Please Click to Read More..." comes up. This way if I forget to do an excerpt it won't be blank. Code I have right now is:

    <div>
    <?php if (the_excerpt == '') : ?>
    <?php echo '<h2><b>Please Click Title to Read More...</b></h2>'; ?>
    <?php else : ?>
    <?php echo sb_clean($post->post_excerpt, 265); ?>
    <?php endif; ?>
    </div>

    Please help I'm still a noob

  2. t31os
    Member
    Posted 3 years ago #

    By default, using the excerpt will not output image attached to a post...

    If you use....

    the_excerpt();

    By default if the excerpt field is empty then it grabs the first 55 characters of your post, excluding images and the associated code.

    If the field has content then it is displayed...

    So you only need this///

    <?php the_excerpt(); ?>
    <h2><strong>Please click title to read more....</strong></h2>

    Unless you need to trim the excepr output you're making this harder then it needs to be. The excerpt function is pretty good in how it works as standard...

    If the field has text, it displays it, if not then it grabs the first 55 characters of the post, excluding images attached to the post...

    However your read more piece could be a link to read the rest like so...

    <?php the_excerpt(); ?>
    <a class="YOURCLASS" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
            ..read more &raquo;
        </a>

    Then in your style.css

    YOURCLASS {font-size:14px;font-weight:bold}

    Where 'YOURCLASS' is a class name you want to use (proberly not in CAPS - rename it as you choose).

  3. shinchook
    Member
    Posted 3 years ago #

    Thanks a bunch! this work kinda like I want it to. Ultimately the problem I'm having is that if I have an image in the post the parameters for the image are showing up at the beginning of the text. I figured if I just had it show the excerpt I could solve the issue. Then I noticed that if I don't have an excerpt it still shows the image parameters when it defaults to the original post text. So I figured I could try to find a way to print the "Click to read more" if there isn't an excerpt to totally prevent the whole image parameters from printing before the post text.

    Check out the site ill put an image in the post of one without an excerpt

    http://designsbyjot.com

  4. shinchook
    Member
    Posted 3 years ago #

    Nevermind, it works exactly like I wanted except now with the mood post plug in. it show the mood in text with no space before the post text. Hmmmm solve one get another :)

  5. t31os
    Member
    Posted 3 years ago #

    :) Glad it works for you...

    I only happen to know because the theme i've adopted for my site uses the_excerpt so i started reading up on the codex.... and fiddling with it...

    If you can give an example of the new problem i'm sure it's easy enough...

  6. shinchook
    Member
    Posted 3 years ago #

    Current Mood: MischievousSo I downloaded some cool plugin for user pictures and thought everything was super. That was until I realized that everyone can have an avatar except me… the admin… the owner of the page. ARG!

    If you read the actual post a emoticon will come up with the mood selected by the poster. When it shows up on the preview there is no space between the written out version of the mood icon and the actual post text.

    Thanks again

  7. shinchook
    Member
    Posted 3 years ago #

    Also... is there anyway to get the text that get "hidden" to have a "..." at the end?

    my code is:

    <div style="height:120px;overflow:hidden;">

    this is what determines the height of the boxes and also how much is cut off at the bottom of the post preview. Can I add anything to it to put a "..." at the end somewhere?

    Thx again

  8. t31os
    Member
    Posted 3 years ago #

    Does your theme have it's own template file for the plugin, if so can you post the code, it's not hard to adjust i'm sure...

    Regarding add '...' to the end, you need to truncate text, and it really depends on what content you're pulling into that DIV, you'll need a little PHP to truncate the text, but you need something that won't cut off between tags....if indeed you're generating tags inside the DIV.

    *Extra *looked at site while writing this reply*

    You can define the plugin bits using CSS, it has default classes...

    .mood is the mood paragraph for example, and it sits above the post text for me in Firefox... not next to it.

  9. shinchook
    Member
    Posted 3 years ago #

    Its a plugin I installed outside of the theme called cricket-moods. There is a lot of code so I won't post it here.

    As far as the "..." if you look at the code above all its doing is hiding anything that doesn't fit in the box height. I actually sized it down a bit from the original and noticed that if i put in 125px half of the bottom row of text peaks out from the bottom. So I guess the text is still there it is just being hidden. Do you know how I can truncate the text so that all text over so many lines gets truncated and a "..." gets put on the end?

    Also, in your extra, I'm still semi-noobish when it comes to coding. I've been reading lots of books and tutorial but am no way a pro. That last section is getting a bit out of my knowledge can you explain in easy mode?

    Thx again your a big help.

    oh yeah and while I have someone listening who has seen the site... if you look at the upper right you will see the popular posts section. it seems to be giving me a similar issue as I was having with my posts at the start of this conversation. ill post the code in the next message for my "popular-posts.php"

  10. shinchook
    Member
    Posted 3 years ago #

    <?php get_header(); ?>
    <div class="contentLayout">

    <!-- Featured Posts -->
    <?php include (TEMPLATEPATH . "/featured-posts.php"); ?>

    <!-- 4 Popular Posts -->
    <?php include (TEMPLATEPATH . "/popular-posts.php"); ?>

    <div class="content">

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <div class="Post" style="width:47.55%;float:left;"><div class="Post-tl"></div><div class="Post-tr"><div></div></div><div class="Post-bl"><div></div></div><div class="Post-br"><div></div></div><div class="Post-tc"><div></div></div><div class="Post-bc"><div></div></div><div class="Post-cl"><div></div></div><div class="Post-cr"><div></div></div><div class="Post-cc"></div><div class="Post-body"><div class="Post-inner">
    <h2 class="PostHeaderIcon-wrapper"><img src="<?php bloginfo('template_url'); ?>/images/PostHeaderIcon.png" width="24" height="24" alt="PostHeaderIcon"/> " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>

    <?php if (!is_page()): ?>
    <?php endif; ?>
    <div class="PostContent">
    <div style="height:120px;overflow:hidden;">
    <?php $image = get_post_meta($post->ID, 'img', true);
    if ($image == '') : ?>
    <?php else : ?>
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <img class="alignleft" style="margin-right:2px;" width="80px" height="80px" src="<?php echo $image; ?>" alt="<?php the_title_attribute(); ?>" />

    <?php endif; ?>
    <!-- <?php the_content('Read the rest of this entry »'); ?> -->

    <div>
    <?php the_excerpt(); ?>
    <!--<h2>Please click title to read more....</h2>-->
    </div>

    </div>
    "><span class="PostMetadataFooter" style="float: right;border: 1px solid #1E1B14;">Read More</span>

    </div>
    <?php if (!is_page()): ?>
    <div class="PostMetadataFooter">
    <img class="metadata-icon" src="<?php bloginfo('template_url'); ?>/images/PostDateIcon.png" width="17" height="18" alt="PostDateIcon"/> <?php the_time('F jS, Y') ?><?php edit_post_link('Edit', ' | '); ?>
    <img class="metadata-icon" src="<?php bloginfo('template_url'); ?>/images/PostCategoryIcon.png" width="18" height="18" alt="PostCategoryIcon"/> <?php the_category(', ') ?> | <img class="metadata-icon" src="<?php bloginfo('template_url'); ?>/images/PostCommentsIcon.png" width="18" height="18" alt="PostCommentsIcon"/> <?php comments_popup_link('0 »', '1 »', '% »'); ?>
    </div>
    <?php endif; ?>

    <?php if (is_single() && !is_page()): ?>
    <div class="navigation">
    <div class="alignleft"><?php previous_post_link('« %link') ?></div>
    <div class="alignright"><?php next_post_link('%link »') ?></div>
    </div>
    <?php comments_template(); ?>
    <?php endif; ?>
    <?php if (is_page()) edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    </div>
    </div>
    </div>

    <?php endwhile; ?>
    <!-- Page Navigation -->
    <?php include (TEMPLATEPATH . "/navigation.php"); ?>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    </div>

    <!-- Right Sidebars -->
    <?php include (TEMPLATEPATH . '/sidebar.php'); ?>

    </div>

    <div class="clear-float" ></div>

    <div>
    <!-- Footer bar -->
    <?php include (TEMPLATEPATH . "/footer-bar.php"); ?>
    </div>

    <?php get_footer(); ?>

  11. shinchook
    Member
    Posted 3 years ago #

    bump it

  12. shinchook
    Member
    Posted 3 years ago #

    ok one more time then I give up

  13. t31os
    Member
    Posted 3 years ago #

    You'll need to edit the 2 custom files featured and popular posts....

    Though truncating the text will require that you learn some PHP or seek help from the theme author.

    You can always check the existing code in WordPress from examples of truncating text...

    Here's somewhere to start in regard to truncating text though..
    http://www.the-art-of-web.com/php/truncate/

  14. shinchook
    Member
    Posted 3 years ago #

    Thanks a lot! I think this may help me with most of my issues. we will see when I get home from work. If not Ill post again.

  15. shinchook
    Member
    Posted 3 years ago #

    ok got somewhere with the posts and got them to truncate. I still need help with these "popular posts" section. Here is the code for popular-posts.php

    <!-- Most Popular Posts -->
    <div style="padding-top:5px;height:285px">
    <div class="Block"><div class="Block-tl"></div><div class="Block-tr"><div></div></div><div class="Block-bl"><div></div></div><div class="Block-br"><div></div></div><div class="Block-tc"><div></div></div><div class="Block-bc"><div></div></div><div class="Block-cl"><div></div></div><div class="Block-cr"><div></div></div><div class="Block-cc"></div><div class="Block-body"><div class="BlockHeader"><div class="header-tag-icon"><div class="BlockHeader-text">
    Popular Posts
    </div></div><div class="l"></div><div class="r"><div></div></div></div>
    <div class="BlockContent" style="margin-left:-10px;margin-top:-10px;margin-bottom:10px;"><div class="BlockContent-body">

    <?php sb_get_popular_posts(6, '<div class="Post" style="width:360px;height:60px;overflow:hidden;margin-bottom:0px;float:left;"><div class="Post-tl"></div><div class="Post-tr"><div></div></div><div class="Post-bl"><div></div></div><div class="Post-br"><div></div></div><div class="Post-tc"><div></div></div><div class="Post-bc"><div></div></div><div class="Post-cl"><div></div></div><div class="Post-cr"><div></div></div><div class="Post-cc"></div><div class="Post-body"><div class="Post-inner"><div class="PostContent" style="margin-left:-5px;margin-top:-5px;">','</div></div></div></div>',true); ?>

    </div></div></div></div>
    </div>

    is there anyway to replace or modify the output part to just show the title of the post? I tried taking things out and the whole site's template and sizes get thrown off.

    thx

  16. shinchook
    Member
    Posted 3 years ago #

    bump plz

Topic Closed

This topic has been closed to new replies.

About this Topic