How can I remove the first two words and shorten get_the_title()
$title = get_the_title(); $title_array = explode(‘:’, $title); $first_word = $title_array[1]; $total_length_limit = 100; echo mb_substr( $first_word, 0, $total_length_limit ) . ‘…’;
$title = get_the_title(); $title_array = explode(‘:’, $title); $first_word = $title_array[1]; $total_length_limit = 100; echo mb_substr( $first_word, 0, $total_length_limit ) . ‘…’;
Alternative approach: <li class=”cycle-item slide-<?php echo $i; ?>”> <span class=”featured-title”><?php the_title(); ?></span> <a href=”https://wordpress.stackexchange.com/questions/97055/<?php the_permalink();?>”><?php the_post_thumbnail(‘featured’); ?></a> </li> then hide the span with CSS, show it on hover of the <li> element, position it over the image with CSS. Example: li.cycle-item { position: relative; } li.cycle-item .featured-title { display: none; } li.cycle-item:hover .featured-title { display: … Read more
Damn, I came with a solution after I posted it…. echo ‘ <a href=”http://www.bing.com/search?q=’ . urlencode($titletest) . ‘”>’ . $titletest . ‘</a>’;
This kind of works but it is outputting 1 post title in particular and for all the images on the page. Any thoughts as to why its not dynamically picking up each images associated post title? $attachments = get_posts( $args ); foreach ( $attachments as $image ) { // Get the parent post ID $parent_id … Read more
Try <?php echo get_the_title(1).’: ‘.single_term_title(”, false); ?> From the Codex the second argument of single_term_title determines whether to “Display the title (TRUE), or return the title to be used in PHP (FALSE). Default: TRUE”
Try this as your query: $args = array( ‘post_type’ => ‘press’, ‘posts_per_page’ => 20 ); $wp_query = new WP_Query( $args ); while // etc. Also you could try: <div class=”press-title”><?php echo get_the_title(); ?> </div>
the_post_thumbnail() and get_the_post_thumbnail() will output the complete HTML for displaying that image. So this <img class=”img-responsive” src=”https://wordpress.stackexchange.com/questions/274181/<?php the_post_thumbnail(); ?>” alt=””> will be rendered to something like this <img class=”img-responsive” src=”https://wordpress.stackexchange.com/questions/274181/<img src=”…” alt=”..” class=”..”>” alt=””> which is not valid HTML and you can’t really tell how browsers will display this. Now you have 2 choices: Use … Read more
There’s a second argument passed to the_title filter, which is the ID of the post the filter is currently operating on. This is important, as you’ve discovered, because the filter runs any time a title is output- in a menu item, widget, any secondary query, etc., so you need to check if that post ID … Read more
As you are using two loops in a page, that’s why you need to reset your query. wp_reset_postdata() -> best used after custom or multiple loops created with WP_Query wp_reset_query() -> best used after a query_posts loop to reset a custom query rewind_posts() -> best for re-using the same query on the same page Get … Read more
Like this: ‘alt’ => get_the_title(). ‘ review’ So the full code would be: <?php the_post_thumbnail(‘250px’, array(‘class’=>”review-siteshot”, ‘alt’ => get_the_title(). ‘ review’ )); ?>