0

I am trying to tweak the bootstrap basic theme so that it shows excerpts. It does it when using search but not by default.

I am trying to figure out what I need to change on the content.php file. Could someone please advise.

I have been trying for hours and am struggling. Code below:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>

    <?php if ('post' == get_post_type()) { ?> 
    <div class="entry-meta">
        <?php bootstrapBasicPostOn(); ?> 
    </div><!-- .entry-meta -->
    <?php } //endif; ?> 
</header><!-- .entry-header -->


<?php if (is_search()) { // Only display Excerpts for Search ?> 
<div class="entry-summary">
    <?php the_excerpt(); ?> 
    <div class="clearfix"></div>
</div><!-- .entry-summary -->
<?php } else { ?> 
<div class="entry-content">
    <?php the_content(bootstrapBasicMoreLinkText()); ?> 
    <div class="clearfix"></div>
    <?php 
    /**
     * This wp_link_pages option adapt to use bootstrap pagination style.
     * The other part of this pager is in inc/template-tags.php function name bootstrapBasicLinkPagesLink() which is called by wp_link_pages_link filter.
     */
    wp_link_pages(array(
        'before' => '<div class="page-links">' . __('Pages:', 'wmillock') . ' <ul class="pagination">',
        'after'  => '</ul></div>',
        'separator' => ''
    ));
    ?> 
</div><!-- .entry-content -->
<?php } //endif; ?> 


<footer class="entry-meta">
    <?php if ('post' == get_post_type()) { // Hide category and tag text for pages on Search ?> 
    <div class="entry-meta-category-tag">
        <?php
            /* translators: used between list items, there is a space after the comma */
            $categories_list = get_the_category_list(__(', ', 'wmillock'));
            if (!empty($categories_list)) {
        ?> 
        <span class="cat-links">
            <?php echo bootstrapBasicCategoriesList($categories_list); ?> 
        </span>
        <?php } // End if categories ?> 

        <?php
            /* translators: used between list items, there is a space after the comma */
            $tags_list = get_the_tag_list('', __(', ', 'wmillock'));
            if ($tags_list) {
        ?> 
        <span class="tags-links">
            <?php echo bootstrapBasicTagsList($tags_list); ?> 
        </span>
        <?php } // End if $tags_list ?> 
    </div><!--.entry-meta-category-tag-->
    <?php } // End if 'post' == get_post_type() ?> 

    <div class="entry-meta-comment-tools">
        <?php if (! post_password_required() && (comments_open() || '0' != get_comments_number())) { ?> 
        <span class="comments-link"><?php bootstrapBasicCommentsPopupLink(); ?></span>
        <?php } //endif; ?> 

        <?php bootstrapBasicEditPostLink(); ?> 
    </div><!--.entry-meta-comment-tools-->
</footer><!-- .entry-meta -->

0

The answer is in your code. It’s even documented:

<?php if (is_search()) { // Only display Excerpts for Search ?> 
<div class="entry-summary">
    <?php the_excerpt(); ?> 
    <div class="clearfix"></div>
</div><!-- .entry-summary -->
<?php } else { ?> 
<div class="entry-content">
    <?php the_content(bootstrapBasicMoreLinkText()); ?> 
    <div class="clearfix"></div>
    <?php 
    /**
     * This wp_link_pages option adapt to use bootstrap pagination style.
     * The other part of this pager is in inc/template-tags.php function name bootstrapBasicLinkPagesLink() which is called by wp_link_pages_link filter.
     */
    wp_link_pages(array(
        'before' => '<div class="page-links">' . __('Pages:', 'wmillock') . ' <ul class="pagination">',
        'after'  => '</ul></div>',
        'separator' => ''
    ));
    ?> 
</div><!-- .entry-content -->
<?php } //endif; ?> 

There is clearly stated in the comment, that the if statement in the first line of code above is telling, that the excerpt should be shown only for search.

So what do you have to do? You have to modify the condition inside that if. How? It depends on what do you want to achieve...

If it should be shown on search and categories, you can use:

if (is_search() || is_category())

If it should be shown on every list of posts, then you can use negation of is_singular().

Here’s the full list of conditional tags.

  • Thanks very much for your reply. is_singular didn't work but have found that I needed to change it to is_home(). That worked so I then changed the code to (is_search() || is_home()) so that both work. – Gary Mar 16 at 12:01
  • @Gary Yes, you should modify that condition so it matches your needs. That’s why there’s a link to list of all conditional tags ;) – Krzysiek Dróżdż Mar 16 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.