So I have this custom widget where you can select a page from a drop box and the widget will lead you to this page. The problem is i have no idea how to display the page's attachment image.
wp_get_attachment_image($page, 'full') doesn't work. In the codex there's an example with a loop, but here I need just that one image.
// This is where you run the code and display the output
$page = $instance['selected']; ?>
<a href="<?= get_the_permalink($page); ?>">
<?php wp_get_attachment_image( $page, 'full' ); ?>
<article>
<h2><?php echo $title; ?></h2>
<h3><?php echo $instance['content']; ?></h3>
</article>
<div class="readmore">Read more</div>
</a>
<?php
echo $args['after_widget'];
}
Okay, I found the solution to my problem
echo get_the_post_thumbnail($page,array(540,260));
Related
I am using a filterable plugin for portfolio items. This is the part of the code that display the thumbnail of each portfolio item and the title of the post. The link when is pressed is opens the image bigger but I would want that link to go to each portfolio item corresponding to the image thumbnail.
What would I have to modify?
<div class="view view-first <?php ps_the_terms(); ?>">
<?php ps_post_thumb(array(400,300)); ?>
<div class="mask">
<h2><?php the_title(); ?></h2>
<p><?php echo ps_post_excerpt(80); ?></p>
<a rel="colorbox" href="<?php the_permalink(); ?>" class="">View Details +</a>
</div>
</div>
<a rel="colorbox" href="<?php the_permalink(); ?>" class="">View Details +</a>
Remove rel="colorbox" as that's probably what the JavaScript is using for a hook.
You may also need to change <?php the_permalink(); ?> if that doesn't already go to the portfolio item.
If the permalink is not using the post link try:
<?php echo post_permalink( $ID ); ?>
https://codex.wordpress.org/Function_Reference/post_permalink
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.
To explain my problem better, I'll begin by pasting the code that I use in a custom template for the front page which pulls the excerpts from the latest blog post and a specific page which has excerpts enabled. It all works great, apart from the actual adding of the "Read More " link which would link to the latest blog post or the specific page.
<?php
$id=163;
$post = get_post($id);
$title = apply_filters('the_title', $post->post_title); ?>
<h3><?php echo $title; ?></h3>
<?php $content = apply_filters('get_the_excerpt', $post->post_excerpt);
echo $content;
?>
This is for the Pages excerpt. I'm stuck to what to implement for the "Read More" in the loop. And below is the code for pulling the latest blog post.
<?php
$latest_post = new WP_Query("showposts=1");
if($latest_post->have_posts()) :
?>
<?php
while($latest_post->have_posts()):
$latest_post->the_post();
?>
<h4><?php the_title() ?></h4>
<?php the_excerpt(); ?>
<?php endwhile ?>
<?php endif ?>
What I would like to do is to add "Read More" links to their respective posts/pages to these two functions. I'm a little bit stuck on how to get this working and I've tried a few different functions and they all did not work.
I look forward to hearing back from you on this particular problem.
James
you can have custom read more link
<?php
$id=163;
$post = get_post($id);
$title = apply_filters('the_title', $post->post_title); ?>
<h3><?php echo $title; ?></h3>
<?php $content = apply_filters('get_the_excerpt', $post->post_excerpt);
echo $content;
?>
<a href="<?php echo get_permalink() ?>" />Read More </a>
<?php
?>
In the page Excerpt
<?php
$latest_post = new WP_Query("showposts=1");
if($latest_post->have_posts()) :
?>
<?php
while($latest_post->have_posts()):
$latest_post->the_post();
?>
<h4><?php the_title() ?></h4>
<?php the_excerpt(); ?>
<a href="<?php echo get_permalink() ?>" />Read More </a>
<?php endwhile ?>
<?php endif ?>
I have a couple of posts that have YouTube videos embedded in them. I only want the videos to show up on the full version of the post. On the category page that lists the posts, I don't want the video to appear.
Here is the site: http://tsa-watch.com/
and the full version of the post:
http://tsa-watch.com/2013/03/25/tsa-makes-double-amputee-marine-remove-prosthetic-legs-during-screening/
Here is a bit of code I use in functions.php to remove the first image from a post ONLY if it is listed on a category page:
function remove_first_image ($content) {
if (is_category()) {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
$content = preg_replace("/<object[^>]+>/i", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image');
Also, here is the loop that I am using on my index.php and category.php files:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="votes" style="min-width:60px"><strong>VOTES:</strong><?php wdpv_vote(false); ?></div>
<div class="alignleft" style="max-width:590px">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<div class="byline"><?php the_time('F jS, Y') ?> by <?php the_author() ?> in <?php the_category(', ') ?> <strong>:</strong> <?php comments_number( 'No Comments', '1 Comment', '% Comments' ); ?></div>
<div class="excerpt">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(array(115,115));
}
?>
<?php the_content('Read more ยป'); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1>Not Found</h1>
<p><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
Any help would be appreciated...
This is a WordPress site I believe?
If so you need to look at editing the theme template file that is responsible for showing the preview of your post on the category pages and remove the section where it is showing images/videos from the post.
Unfortunately not knowing what theme it is you are using or what the file names are called it's hard to tell but look for a page template which has the word home or categories in it or open up the category.php from within your activated theme folder if you have them to see if you can find something related to this and comment it out to see if it fixes it.
Also try adding the following inside your custom function:
$content = preg_replace("/<embed[^>]+>/i", "", $content, 1);
I wish to get the title, the excerpt and some meta from three different pages that all have the same parent.
I do not wish to specify wich three pages to show but rather show the three that was last edited/published.
I aim to display the content as three blocks on a horizontal line.
As I was unable to get the code to work:
<ul id="">
<?php query_posts("posts_per_page=1&post_type=page&post_parent=4"); the_post(); ?>
<li>
<img src="<?php echo get_post_meta($post->ID, "image", true); ?>" alt="<?php the_title(); ?>" />
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</li>
</ul>
Thank you Dan, this still does not work though. The excrept of the first page does not show (the title shows and the meta also). Tried the code below with the same result except that the second time the content is displayed, the excerpt of the first page shows.
<?php get_header(); the_post(); ?>
<div id="main-content">
<?php
$categoriesCF = get_post_meta($post->ID, "categories", true);
$allCategories = explode(",", $categoriesCF);
foreach ($allCategories as $category) {
$pieces = explode("|", $category);
$link = get_permalink($pieces[1]);
echo "<div class='product-group group'>";
echo "<h3><a href='$link'>" . $pieces[0] . "</a></h3>";
query_posts("posts_per_page=-1&post_type=page&post_parent=$pieces[1]");
while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" class="product-jump" title="<?php the_title(); ?>" data-large="<?php get_post_meta($post->ID, "image", true); ?>">
<?php echo "<img src='" . get_post_meta($post->ID, "image", true) . "' />"; ?>
<span class="product-title"><?php the_title(); ?></span>
<span class="product-title"><?php the_excerpt(); ?></span></a>
<?php endwhile; wp_reset_query();
echo "</div>";
};
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>`
Change posts_per_page to 3 and use orderby=date&order=DESC to get the 3 most recent.
If you are displaying this on a page that already shows some other post/page/posts/pages, use get_posts instead of query_posts.
The WordPress codex has full documentation and examples for all of these things:
http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Function_Reference/get_posts