ThemeShaper Forums » Thematic

[closed]

Apply "excerpt" on post in a static page

(7 posts)
  • Started 2 years ago by larand54
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. larand54
    Member

    Hello,
    The first page on my site is static with a single post as the content. But the size of the content area should be restricted so if the text of this post is too long it should be replaced with an excerpt.
    That's easy to achieve but the "read more"-link should not point back to the same page but to another page where the complete post could be read. That was the hard part which is my problem.

    Don't ask me why I need to do this, it's not my idea :-), I only want some idea how I could solve this. I'm sure there will be a lot of solutions and I'm eager to read them all ;-).

    Thanks in advance

    Posted 2 years ago #
  2. proto
    Member

    Hi there larand54,

    If I understand correctly you'd like the "Read More" bit to appear below the post so that when a user clicks on it they are then take to the full post content?

    So one way to do this is to use the php tag which refers to the permalink, like so:

    <?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more">
    <?php echo more_text() ?></a>

    So in a full loop (obviously you'd have to end the loop with the appropriate endwhile else etc - I'm excluding these from this example as assume that your ok with how to end the loop etc):

    <div id="yourpost" class="yourclass">
    <?php query_posts('category_name=kids-furniture-
    &posts_per_page=1');?>
     <?php while (have_posts()) : the_post(); ?>
    <h1 class="postheader"><a href="<?php the_permalink() ?>"
    rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title(); ?></a></h1>
    <div class="entry-content">
    
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more">
    <?php echo more_text() ?></a>
    	 </div><!-- end of Entry Content -->
    
    <?php endwhile; ?>
    </div>

    Hope that makes sense :)

    More on loops here, just in case: http://codex.wordpress.org/The_Loop

    Posted 2 years ago #
  3. larand54
    Member

    Thanks for the quick answer,

    It's not so easy as I use the thematic and therefore need to override the "thematic_index_loop" using the function "childtheme_override_index_loop()" in my childthemes functions.php.

    I copied the complete code from the original function and added the "query_posts" function to select the post with the wanted category.

    The problem is that this post shows up as a ordinary post with all that include references to comments etc. The old post belonging to the page is also printed even though it didn't have the selected category.

    function childtheme_override_index_loop() {
    global $options, $blog_id, $cat;

    foreach ($options as $value) {
    if (get_option( $value['id'] ) === FALSE) {
    $$value['id'] = $value['std'];
    } else {
    if (THEMATIC_MB)
    {
    $$value['id'] = get_option($blog_id, $value['id'] );
    }
    else
    {
    $$value['id'] = get_option( $value['id'] );
    }
    }
    }

    if ( is_front_page() ) {
    query_posts('category_name=intro-&posts_per_page=1');
    }
    /* Count the number of posts so we can insert a widgetized area */ $count = 1;
    while ( have_posts() ) : the_post();
    $cat = get_the_category(); $cat =$cat[0]; $scat = $cat->category_nicename;
    thematic_abovepost(); ?>

    <div id="post-<?php the_ID();
    echo '" ';
    if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
    post_class();
    echo '>';
    } else {
    echo 'class="';
    thematic_post_class();
    echo '">';
    }
    thematic_postheader(); ?>
    <div class="entry-content">
    <?php thematic_content(); ?>

    <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->

    <?php

    thematic_belowpost();

    if (!is_front_page() and !($scat == 'intro')) {
    comments_template();
    } else {
    wp_reset_query();
    }

    if ($count==$thm_insert_position) {
    get_sidebar('index-insert');
    }
    $count = $count + 1;
    endwhile;
    wp_reset_query();
    }// end index_loop

    Well, I have labbed a lot but no success :-(

    Posted 2 years ago #
  4. proto
    Member

    Hi larand54,

    I'm not sure what you're asking for in your latest message? What's the exact problem and what would you like to have happen instead?

    If you're wanting to display just an excerpt then use the following code, where you'd like the extract to appear in place of the full content. So you might want to try using this code

    CODE 1 SNIPPET:

    <?php the_excerpt(); ?>
    <a href="<?php the_permalink(); ?>" class="more">
    <?php echo more_text() ?></a>

    and place it and instead of where you're outputting the full content:

    CODE 2 SNIPPET:

    <?php thematic_content(); ?>

    From your above code I think you may be telling Thematic to display the full content. So try replacing code 2 (that appears in your long loop above) with code 1 and see if that gets what you want (still not 100% sure exactly what you want?)

    Perhaps a link to your live site so we can see the issue that you're having? You could have your homepage display whatever you want by having a loop for example in your child theme functions that you call in your "home.php" file.

    The code I gave you should insert the "Read more" text I think you were after from reading your first post? I thought that's what you were after? If you're not familiar with the loop the codex on it is really good, it gives you live working examples:

    http://codex.wordpress.org/The_Loop

    Hope that helps :)

    Posted 2 years ago #
  5. larand54
    Member

    I think your solution will solve this particular problem but as I'm using a lot of the thematic's other sections and I will loose several of them if I use your code. I'll try to make up a simple live site tomorrow to show you my problem. It's been a long day and I'm to tired to continue so I have to leave it until tomorow.

    thanks!

    Posted 2 years ago #
  6. proto
    Member

    Hi larand54,

    No problem at all. I've had so much help on here, I try and give back when I can! You don't have to change the default loop of thematic.

    If you're developing your theme as a child theme (there's literally a million reasons why everyone who is working with thematic should almost certainly use a child theme to do so!) More here on how to do this ( http://themeshaper.com/thematic/guide/?page_id=66 ). You can have a custom loop (one you design, display exactly where you want - eg just the homepage have a post show up in a certain way - eg just as an excerpt). You don't even have to touch or alter the thematic default loop.

    If you create, for example, a home.php file and call within that a loop you've created in your child theme's functions.php file then you are pretty much only limited by your imagination as to what / how you want to display something. Loops take a while to get familiar with, but once you are there's no looking back! ( more info here: http://codex.wordpress.org/The_Loop )

    Once you've read both these links getting what you want will probably take some learning but you will really see the power of a child theme and custom loops!

    Hope this helps!

    And yes any live site links appreciated :)

    Posted 2 years ago #
  7. you could copy page.php into your theme folder and rename it front-page.php
    http://codex.wordpress.org/Template_Hierarchy#Front_Page_display

    then modify the query for that page either manually in the template or by tweaking the query at the pre_get_posts() hook. http://codex.wordpress.org/Custom_Queries

    then you might have to filter thematic_content to show excerpts there.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.