So I've been trying to figure this out for a while now, and I'm guessing some advanced filters and stuff are involved, but here goes. How can I make the "read more" button that I coded into the content loop in my Wordpress blog display:none when I'm using the < !--more--> tag manually?
When I'm using it now, both "read more" buttons are visible.
<div class="entry-content">
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
<?php endif; // is_single() ?>
<div class="entry-meta">
<span><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></span>
</div>
<img class="post-icon" src="<?php echo get_template_directory_uri(); ?>/images/pencil.png">
<div class="seperator">
<div class="sepen"></div>
<div class="septo"></div>
</div>
<div class="entry-excerpt">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php the_content( __( 'read more <span class="meta-nav">→</span>', 'dsgn' ) ); ?>
<?php echo '".__( '<span>read more</span>', 'dsgn' ). '' ?>
<div class="entry-footer-fix"></div>
</div>
You are outputting two "read more" tags. Stop doing this:
<?php echo '".__( '<span>read more</span>', 'dsgn' ). '' ?>
the_content() will already output a "read more" tag. It takes your desired "read more" snippet as an argument and automatically decides whether to show either the entire post or just the first part along with your given "read more" snippet. As mentioned in the documentation, you can override the automatic behavior (force entire/partial content) by changing the global variable $more.
In other words, you should never need to echo your own "read more" tag unless you always want to it to be visible.
Related
here is what I want to do:
I have a blog post which I want to display only to a specific point. So in the post I put
<!--more-->
on the right position.
My content.php looks like this:
<div class="entry-content">
<?php the_content('read more'); ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->
The "read more" link gets displayed right after the content where it should be. But how can I display it inside the entry footer with the "Comment" link?
Is there a solution with the excerpt?
<?php the_excerpt(); ?>
I think this would even be better because I wouldnt need to put the line in every post.
You can remove the 'read more' by using the following filter in your functions.php:
add_filter( 'the_content_more_link', 'remove_more_link', 10, 2 );
function remove_more_link( $more_link, $more_link_text ) {
return;
}
Now you can create your own read more link inside entry-footer:
<footer class="entry-footer">
<a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a>
<?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->
Edit:
In comments below the following question was asked:
I used the_excerpt() instead of the_content(). Is it possible to only display the link if the post is actually too long?
You can do this by checking if the excerpt is different from the content. If this is the case (so there is more content than the excerpt is showing) you can show the read more link:
<?php if ( get_the_content() != get_the_excerpt() ){ ?>
<a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a>
<?php } ?>
I use one workaround:
//REMOVE 'MORE' LINK AND HARDCODE IT INTO PAGE - TEASER JUST PLAIN ELLIPSIS
function modify_read_more_link() {
if ( is_front_page() ) {
return '...';
} else {
return '</div><footer class="clearfix"><a class="mg-read-more" href="' . get_permalink() . '">Continue Reading <i class="fa fa-long-arrow-right"></i></a>';
}
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
Explanation: for front page I have a short overview only clickable in the post title. And for blog list (after else in the above function.php ):
<article>
<header></header>
<div>
<?php the_content(); ?>
</footer>
</article>
In which you can notice missing div closing and footer opening tags. It is a bit messi, but it brings the original Wordpress Teaser into next division.
Thankyou for reading.
I have created a sidebar.php-file with the code;
<section class="sidomeny"><p class="Senastenytt2"><?php get_search_form();?></p></section><!--Slut på sidomeny-->
<div id="nyhet3">
<?php
query_posts('category = all');
if (have_posts()) :
while (have_posts()) : ?>
<?php the_post(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<?php the_excerpt(); ?>
<p class="textnyhet2"></p>
<?php
endwhile;
endif;
?>
</div><!--Slut på Nyhet3-->
And now I would like to add the function that if you press the sidebar news section, the "textnyhet2" section will get updated with the news you clicked on. That is how it's working now.
But the problem is that the sidebar vanished whenever you click on one of those "latest news" links. So what I need help with is to edit the sidebar.php-file so the "latest news" function with links is still there so you don't have to go back one page whenever you would like to read about another post.
Im not sure how to do this. If it's php involved or if you can do it by simple visiting the posts/pages section in wordpress.
Would be grateful if anyone could help me. If I have forgotten any necassary information please tell me and I will the post.
Thanks!
<?php
get_header();
?>
<section class="textinnehall">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;?>
</section>
<section class="sidomeny">
<?php
get_sidebar(); ?>
</section>
<?php
get_footer();
?>
This is my page.php file. Don't know if it will be to any help. But the sidebar is already active.
May be the sidebar is not called in your single page.
you need to have the same design in your themes single.php page(As per twenty ten theme standard).
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
The href <?php the_permalink() ?> takes the post to single page for full view
Just call the sidebar in your theme's single page.
EDIT:
I have a custom php function setup to show the wordpress post excerpt and when the read more link is clicked the excerpt is hidden and the main content displayed. However i want the read more button to become a hide button for when the content is expanded.
<?php the_excerpt();
echo '<a value="show more..." onclick="$(this).prev().hide(); $(this).next().show();" >Read More</a>';
echo '<div style="display:none">';
echo the_content();
echo '</div>'; ?>
to keep it simple, you can do something like this:
<div id="shortcontent">
<?php the_excerpt(); ?>
Read more
</div>
<div id="fullcontent" style="display: none">
<?php the_content(); ?>
Hide
</div>
What I want to know is, how can I implement my already made index.php file to apply custom posts to it. (See below)
What I want to accomplish:
Display all posts(already accomplished in index.php)
--> show normal post a.k.a 'Article' (already accomplished in index.php)
If category/or post type 'Aside' is used, don't apply a <a> tag, make title lighter(can figure it out in CSS)
-->show text for the 'Aside' marked post
If category/or post type 'Link' is used, wrap title in <a> tag linking to a site(<-- how would I do that in WordPress?)
-->show text for info about the link
If category/or post type 'Photo' is used, don't wrap title in a <a> tag
-->show attached image in post, and post text as a caption
I know this may look like a lot but I'm sure it's easily do-able.
Some source code may not help me all the way, so I have my index.php below to see if you can help me implement it into it:
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<article>
<!-- <p><span class="metaCat"><?php the_category(', '); ?></span></p> -->
<h1><?php the_title(); ?></h1>
<p><span class="meta"><?php the_time('F jS, Y') ?></span></p>
<hr />
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
</div>
</article>
<hr class="big" />
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
If you can input the needed code into a workable index.php file you will get some well thought of brownie points!
Thanks and all help is welcomed!
I finally see what you meant to do here. This is easily done using the get_post_format() function. Just replace the title here with:
<?php
$format = get_post_format(get_the_ID());
if ($format == 'link') { ?>
<h1><?php the_title(); ?></h1>
<?php }else{ ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
The other bit about linking to a site though, I'm not sure how you want to accomplish that. Are you referring to the blogroll?
The best option for the "link" post format, is to use a custom metabox/custom fields. Add your key as "URL" then type the address in the value field.
Use get_post_meta() to get the URL and use that instead of the_permalink() in the href.
<?php query_posts($query_string . '&orderby=rand') ?>
Hey all,
I've tried to implement the above piece of code into my portfolio page template.php.
http://www.some-things.net/category/work/
It's causing the css to break every so often. Reload it until it breaks and you will see what I mean. It pushes 2 of the portfolioitem blocks to the right a touch and forces the third to drop a line?
<div style="clear:both"></div>
<div class="gallery">
<?php query_posts($query_string . '&orderby=rand') ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="portfolioItem">
<a href="<?php the_permalink() ?>" class="desctitle" title="<?php the_title();?>"><?php the_post_thumbnail(); ?>
<span class="desctitle"><?php the_title(); ?></a>
</span>
</div>
<?php endwhile; ?>
</div>
The error isn't in the random layout code. It's caused by an empty "tile" in your page. here's the source of the offending tile:
<div class="portfolioItem">
<span class="desctitle">Love Jungle</span>
</div>
Notice there's no image.