On the main page in Wordpress I use multiple excerpts of different pages. The problem is though that it returns everytime the same excerpt link. It seems like the last link (of 3) on the page is used everytime.
The code (of course I changed the number of the id everytime ;-) :
<?php
$post_id = 35; // post id
$queried_post = get_post($post_id);
$my_excerpt = get_excerpt_by_id_long($queried_post); //$post_id is the post id of the desired post
echo '<a href="' . get_permalink( $queried_post ) . '" title="' . $queried_post->post_title . '">';
echo '<h3><strong>';
echo $queried_post->post_title;
echo '</strong></h3>';
echo '</a>';
echo $my_excerpt;
?>
This is in functions.php
function get_excerpt_by_id($post_id){
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
$excerpt_length = 35; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '…');
$the_excerpt = implode(' ', $words);
endif;
$the_excerpt = '<p>' . $the_excerpt . '<a class="leesmeer" href="'.get_permalink($post_id).'">lees verder...</a></p>';
return $the_excerpt;
}
never mind, I found the solution: forgot to use the $post_id in the .get_permalink()...Edited the code in the above functions.php
I have got a comment from someone superior to me who wants me to escape some comment in two php snippets which I have posted below. The problem is I don't know how to do that. Can anyone help me by modifying the snippets.
Comment I got:
Comment #1:
Validate and/or sanitize untrusted data before entering into the database. All untrusted data should be escaped before output.
Code Snippet #1:
<?php
if ( get_header_image() && !('blank' == get_header_textcolor()) ) {
echo '<div class="site-branding header-background-image" style="background-image: url(' . get_header_image() . ')">';
} else {
echo '<div class="site-branding">';
}
?>
Code Snippet #2:
<?php
printf(
/* translators: %1$s = text link: sangeet, URL: http://wordpress.org/themes/sangeet/, %2$s = text link: Kiran Kumar Dash, URL: https://twitter.com/TheKiranDash */
__( 'Theme: %1$s by %2$s', 'sangeet' ),
'' . esc_attr( 'sangeet', 'sangeet' ) . '',
'' . esc_attr__( 'Kiran Kumar Dash', 'sangeet' ) . '' );
?>
Comment #2:
esc all get_permalink() in content.php
Code snippet #3
<?php
if ( !is_single() ) {
echo '<div class="index-box">';
if ( has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . get_permalink() . '" title="' . __('Read ', 'sangeet') . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
}
?>
My approach:
I used esc_url to esc the get_permalink() in the snippet. Shall I use esc_all? Or esc_url is just fine.
<?php
if ( !is_single() ) {
echo '<div class="index-box">';
if ( has_post_thumbnail()) {
echo '<div class="small-index-thumbnail clear">';
echo '<a href="' . esc_url(get_permalink()) . '" title="' . __('Read ', 'sangeet') . get_the_title() . '" rel="bookmark">';
echo the_post_thumbnail('index-thumb');
echo '</a>';
echo '</div>';
}
}
?>
As requested:
PS. I didnt write this, only advanced it.
Usage:
$user = sanctify($_GET['user']);
Function:
function sanctify($data){
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&','<','>'), $data);
$data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
$data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
// Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
$data = str_replace('"','',str_replace("'","",$data));
do{
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
}
while ($old_data !== $data);
// we are done...
return $data;
}
hi there is a code in below
function sumobi_edd_show_download_sales() {
$sales = edd_get_download_sales_stats( get_the_ID() );
$sales = $sales > 1 ? $sales . ' sales' : $sales . ' sale';
echo '<p>';
echo $sales;
echo '<br/>';
echo sumobi_edd_get_download_count( get_the_ID() ) . ' downloads';
echo '</p>';}add_action( 'edd_product_details_widget_before_purchase_button', 'sumobi_edd_show_download_sales' );
i need to diplay output of this code to another file
In Wordpress 3.5.1 I want to create & use custom layout to display search result. I googled and found http://codex.wordpress.org/Creating_a_Search_Page but this is not exactly what I want.
Okay I solved my problem and now very happy :)
I write following script in search.php file
while ( have_posts() ) {
the_post();
//get_template_part( 'content', get_post_format() );
$permalink = get_permalink($post->ID);
$title = get_the_title($post->ID);
$feed = truncate( strip_tags( get_the_content($post->ID) ), 0, 300, "[...]");
echo '<div class="posts">';
echo '<div style="float:left">';
echo '<a class="featured-img">
'.the_post_thumbnail('thumbnail').'
</a>';
echo '</div>';
echo '<div class="posts-content">';
echo '<div class="heading">'.$title.'</div>';
echo '<div class="comments"> </div>'.
$feed
.'</div>';
echo '</div>';
}
I am trying to figure out a way to remove permalink's from posts with the category 'nolink'. I have tried a few java script attempts - but have not managed to get it to work.
<?php
query_posts( 'tag=Client-list' );
while ( have_posts() ) : the_post();
echo '<ul class="client-thumb-wrap">';
echo '<a href="';
the_permalink();
echo '">';
echo '<li class="';
$category = get_the_category( $custompost );
echo $category[0]->cat_name ;
echo ' ';
echo $category[1]->cat_name ;
echo ' ';
echo $category[2]->cat_name ;
echo ' ';
echo $category[3]->cat_name ;
echo '">';
echo '<img src="';
the_field('client_logo');
echo '">';
echo '</li>';
echo '</ul>';
endwhile;
wp_reset_query();
?>
has_term allows you to check if a post has a specific term assigned (or not), try:
$href = ( has_term( 'nolink', 'category' ) ) ? '#' : get_permalink();
echo '<a href="' . $href . '">';