last word of excerpt as a link - wordpress

Does anybody know how to do this ? I would like to use last word of post excerpt as a link to it (post). Just like in text below:
Curabitur porttitor sem quis ipsum rutrum pharetra. Aliquam molestie justo eget nibh vulputate placerat. Etiam aliquet augue sit
solved :)
function excerpt_read_more_link($output) {
global $post;
$output_array=explode (' ',$output);
$count_words=count ($output_array);
$last_word=$output_array[$count_words-1];
for ($i=0; $i<$count_words-1;$i++)
{ $new_output.=$output_array[$i]." ";}
return $new_output . ''.$last_word.'';
}
add_filter('the_excerpt', 'excerpt_read_more_link');

Related

Is it possible to find and style one character in a span with pure CSS? [duplicate]

This question already has answers here:
Style certain characters with CSS
(5 answers)
Closed 3 years ago.
I think the answer here is "no", but some of the tricks css3 pseudo selectors can be harnassed to perform come close to magic at times.
I want to find and style the period character inside spans. Don't ask why, the context is ridiculous. Sadly the character can't be relied upon to exist in the same position on each occasion, so it has to be found. I think without JS this can't be done but wanted to confirm.
Overall no... however you could wrap each character in an element, which you can then style.
A simple bit of JS can be used to do this.
const el = document.querySelector("#find-periods");
el.innerHTML = el.innerHTML.replace(/\./g, '<span class="char-period">.</span>')
.char-period{ color: red; font-size: 30px; }
<p id="find-periods">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vitae tristique massa, ut convallis risus. Vestibulum maximus sed libero ut lacinia. Integer vel mollis ex. Nullam mattis ipsum in massa aliquet pharetra eget nec enim. In vitae sem at nibh mollis finibus. Quisque id pretium velit. Donec nec augue volutpat, sodales dui id, eleifend augue. Nulla lobortis congue est ut venenatis. Ut mollis nisi ac purus auctor, nec sollicitudin mi vestibulum. Integer tincidunt, metus sit amet euismod porta, nisl nisi accumsan lectus, id lacinia nunc arcu vitae massa. Nunc et tellus ante. In mattis ex sed sem hendrerit elementum. Ut leo libero, convallis sit amet massa et, tincidunt malesuada augue. Pellentesque consectetur maximus maximus. Duis suscipit dolor risus, sed egestas libero iaculis ac. Phasellus consectetur quam ipsum, in finibus leo fringilla a.
</p>

How would I use CSS to change style of element depending on browser language?

Basically, without changing the html if at all possible, I'd like to be able to write a CSS selector that when the browser language = 'ar-sa' or 'ar' it has direction: rtl otherwise it has direction: ltr?
I've found some stuff about language attributes in html, but I'm trying to do this entirely in CSS so I can avoid a site redeploy (I have a mechanism to dynamically drop in CSS)
You can use the :lang() pseudo-selector!
var html = document.documentElement;
var switcher = document.querySelector('#switch-lang');
html.setAttribute('lang', 'ar');
switcher.addEventListener('click', function(e) {
var languageSet = getLang() == 'ar' ? 'en' : 'ar';
html.removeAttribute('lang');
html.setAttribute('lang', languageSet);
});
function getLang() {
return html.getAttribute('lang');
}
html:lang('ar') {
direction: rtl;
}
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Sed posuere consectetur est at lobortis. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Sed posuere consectetur est at lobortis. Cras mattis consectetur purus sit amet fermentum.</p>
<button id="switch-lang" type="button">Switch language</button>
You can not identify the browser language purely with CSS.
The lang attribute for the <html> tag and the dir (direction: ltr, rtl) attribute for the <body> tag can be used to configure the direction.
Example:
body[dir="ltr"] { direction: ltr; }
body[dir="rtl"] { direction: rtl; }

ASP.NET MVC #Html.Raw() not working

I have this line of code here in my view
I have this string #Model.inventory.overview and it has — in it.
When I try to use it so it will display the special html character it shows up as the text —
#Html.Raw(Model.inventory.overview)
and
#MvcHtmlString.Create(Model.inventory.overview)
This is what #Model.inventory.overview is
Lorem ipsum dolor sit—amet, consectetur adipiscing elit.
Mauris eget feugiat nibh. Fusce rhoncus ex et nunc fringilla, ut
fermentum tortor volutpat. Praesent mollis efficitur magna auctor
sollicitudin. Morbi pulvinar, justo ut efficitur rutrum, dui metus
varius magna, vitae molestie leo elit vel turpis. Nullam quis ipsum
nec erat maximus dictum sit amet sed ligula. Vestibulum tincidunt
dolor non—justo accumsan, eu euismod neque rutrum. Donec in
lacinia est.
I have also tried the following:
#Html.Raw(HttpUtility.HtmlDecode(#model.ContentBody));
Still not working.
#Html.Raw(Html.Encode(Model.inventory.overview)) was the solution after all.
I looked at W3C Html ASCII characters list and had a suspicion — wasn't "exactly" a ASCII character, so I found this site soon after. Glad I was helpful.

find shortcode inside content of post

I've a post with a video, contained inside the content. So, the content of my post is like:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur aliquam quam sed imperdiet viverra. In ornare semper nisl, ac sodales metus facilisis ac. Morbi quis erat id magna dapibus consequat. Vestibulum sollicitudin hendrerit nisl sit amet lacinia. Mauris sed sodales quam. Mauris semper, ante quis imperdiet iaculis, neque eros pulvinar eros, id aliquet magna mauris at sapien. Sed sodales, diam venenatis aliquam ornare, nisl lorem accumsan eros, vitae suscipit dolor purus quis odio. Integer quis hendrerit sapien, at pretium neque. Nullam convallis auctor enim et malesuada. Suspendisse id fermentum risus..
[video width="100%" height="360" url="http://www.youtube.com/watch?v=sd1273xA"]"
Where the shortcode is displayed like text... I need to display the video...to use do_shortcode.
I'm trying without luck:
function your_prefix_detect_shortcode()
{
global $post;
$pattern = get_shortcode_regex();
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array( 'video', $matches[2] ) )
{
echo do_shortcode("[$matches[0][0]]");
}
}
add_action( 'wp', 'your_prefix_detect_shortcode' );
EDIT:
The content is called from single.php like:
<p class="titulillos">Descripción: <br><span><?php echo nl2br($post->post_content); ?></span></p>
EDIT2:
I'm having problems with encoding...because when processing the shortcode, for example, height isn't 360px, it's "360"
And the result is a fatal error doing calcs

Drupal Front Page Markup

I'm trying to change the markup around articles being displayed on the front page of a drupal site so I can integrate them into a slideshow. (I can't use a slideshow module). I have a page--front.tpl.php file, but I need to add more specific markup than I can do here.
How do you go about changing the markup for just a specific area of the front page?
I believe I need to write a preprocess hook, but I'm not sure how to target just the articles node on the front page. This is the markup I would like to have generated:
<div class="slidewrap" data-autorotate="5000">
<ul class="slidecontrols">
<li>Next</li>
<li>Prev</li>
</ul>
<ul class="slider" id="sliderName">
<li class="slide">
<h2 class="slidehed">First Slide</h2>
<img src="1.jpg" />
<p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget, scelerisque a libero.</p>
</li>
<li class="slide">
<h2 class="slidehed">Second Slide</h2>
<img src="2.jpg" />
<p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</p>
</li>
<li class="slide">
<h2 class="slidehed">Third Slide</h2>
<img src="3.jpg" />
<p>Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget.</p>
</li>
<li class="slide">
<h2 class="slidehed">Fourth Slide</h2>
<p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio.</p>
</li>
<li class="slide">
<h2 class="slidehed">Fif' Slide</h2>
<p>In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</p>
</li>
</ul>
</div>
I've been trying to do this using the views module. However, when I create a new template I get this error message:
Warning: Invalid argument supplied for foreach() in include() (line 12 of /d7install/path_to_theme/views-view--featured--block.tpl.php).
Here is the template file that I copied via the Theme Information:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes_array[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
there is a simple solution. Add a new template for article content types. node-article.tpl.php. And then add an if statement to that, if the article is on the front page, show markup A, else show markup B. Like:
if (drupal_is_front_page()) {
<article class='front-page'>Article</article>
}
else
{
<article class='other-page'>Article</article>
}
This can all be achieved by the views module: http://drupal.org/project/views
Create a block display and have it show only on the home page. There should be no need for a custom views template.
You can add the .slidercontrols UL to the header of the view. Also if you need the attribute on the outer div just add it via jQuery with something like this.
$('.slidewrap').attr('data-autorotate', 5000);

Resources