How to change text Home to icon Home on WordPress? - php

I want to edit the breadcrumbs of website (MH Themes). It only is change the 'text Home' (in echo line) to 'icon Home' (<i class="fa fa-home" aria-hidden="true"></i>). I have try a ten times but I can't.
<?php
/***** Breadcrumbs *****/
if (!function_exists('mh_magazine_breadcrumb')) {
function mh_magazine_breadcrumb() {
if (!is_home() && !is_front_page()) {
global $post;
$mh_magazine_options = mh_magazine_theme_options();
if ($mh_magazine_options['breadcrumbs'] == 'enable') {
$item_counter = 1;
$delimiter = '<span class="mh-breadcrumb-delimiter"><i class="fa fa-angle-right"></i></span>';
$before_link = '<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">';
$before_title = '<span itemprop="name">';
$close_span = '</span>';
echo '<nav class="mh-breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">' . $before_link . '' . $before_title . esc_html__('Home', 'mh-magazine') . $close_span . '' . '<meta itemprop="position" content="' . $item_counter . '" />' . $close_span . $delimiter;
$item_counter++;

This is what's creating the Home text:
esc_html__('Home', 'mh-magazine')
That needs to be changed into the icon you want to display.

Related

How to get the number of pages of current wordpress post?

I do split the $post_content using <!--nextpage--> as separator, but maybe there is another method to obtain the number of pages of a single post because I'm doing it many times on large posts.
The WP_Post class doesn't have a member like $post_pages or something.
Use this for a link to previous posts with directional:
<?php previous_post_link(); ?>
Or this for a link to previous posts that without "<<":
<?php previous_post_link('<strong>%link</strong>'); ?>
The code needs to be inside the loop.
Or
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" "><strong><<< "'. $prev_title . '"</strong></a>' . "\n";
}
?>
</div>
<div class="next-posts pull-right">
<?
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" class=" "><strong>"'. $next_title . '" >>></strong></a>' . "\n";
}
?>
</div>

WordPress: echoing just the first 60characters of the post title

I am styling a WordPress Theme and I would like to make sure that if the post title is longer than 60 characters it shows the first 6ß0 characters +
three points (...) at the end
In Native Php would like:
<?php
if (strlen($title) <= 60) {
echo %title
} else {
echo (substr($title, 60) . "..."
}
?>
My problem is that inside WordPress the syntax of variables is not $title but %title as you could see in the code:
<?php previous_post_link( '%link', '%title ' ); ?>
My questions are:
How would be the final IF inside WordPress
How would be in shorthand if/else (ternary) form?
Thanks
You achieve this by creating your custom post_nav function
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if ($prev_post)
{
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
if (strlen($prev_title) >= 60) //<-- here is your custom checking
{
$prev_title = (substr($prev_title, 0, 60)) . "...";
}
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title . '" class=" "><strong><<< "' . $prev_title . '"</strong></a>' . "\n";
}
?>
</div>
<div class="next-posts pull-right">
<?php
$next_post = get_next_post();
if ($next_post)
{
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
if (strlen($next_title) >= 60) //<-- here is your custom checking
{
$next_title = (substr($next_title, 0, 60)) . "...";
}
echo "\t" . '<a rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title . '" class=" "><strong>"' . $next_title . '" >>></strong></a>' . "\n";
}
?>
</div>
Hope this helps!

How to add a "active" class to a carousel first element

I'm developing a News website in Wordpress, and I need to show in a bootstrap carousel the first three posts, my problem is that I need to add the "active" class only at the first of the three elements, but really don't know how to. Here's my code:
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
?>
I've already tried a answer found on this site (this one):
$isFirst = true;
foreach ($recent_posts as $recent) {
echo '<div class="item' . $isFirst ? ' active' : '' . '"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ": <strong>" .$recent["post_title"] . '</strong></a></div>';
$isFirst = false;
?>
but it just printed me the "active" words.
Thanks for your help
You need to set $i so that you can count how many times you have gone through the loop and do some logic with it, like in my example below. Instead of having two lines of code that are nearly identical like I have done below though, you should be able to do the if conditional right around the class active. I didn't do that so you could clearly see the conditional and the count of the loops through the array.
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
$i = 0;
foreach ($recent_posts as $recent) {
if ($i == 0) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
} else {
echo '<div class="item"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
$i++;
}
?>

qTranslate inside PHP

There are a few things that won't translate on my website that are inside PHP. Since it's inside PHP, the normal qTranslate quick tag won't work. Is there a simple code that could help me translate these words? Should it go on the same page where the translations are located?
This is the code for the what I need translated inside the PHP (Location:, Venue:, etc):
<div class="event-text">
<h2 class="event-title">' . get_the_title($post->ID) . '</h2>
<ul class="event-meta">';
if ($event_location != null) {
echo '
<li><span>Location:</span>' . $event_location . '</li>';
}
if ($club != null) {
echo '
<li><span>Venue:</span>' . $club . '</li>';
}
if ($event_allday == 'yes'){
echo '<li><span>Length:</span>All Day</li>';
} elseif ($tstart) {
echo '<li><span>Length:</span>' . $tstart . '';
} if ($tend) {
echo ' – ' . $tend . '</li>';
}
echo '
<li>';
if (get_post_meta($post->ID, 'event_out', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Sold Out</p></div><!-- end .event-cancel-out -->';
} elseif (get_post_meta($post->ID, 'event_cancel', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Canceled</p></div><!-- end .event-cancel-out -->';
}elseif (get_post_meta($post->ID, 'event_free', true) == 'yes') {
echo '<div class="event-cancel-out"><p>Free Entry</p></div><!-- end #event-cancel-out -->';
} else {
echo '<div class="event-tickets"><a href="' . $event_ticket . '" >Buy Tickets</a></div><!-- end #event-tickets -->';
}
echo '</li>
</ul><!-- end ul.event-meta -->';
echo '
' . the_content() . '
</div><!-- end .event-text -->';
Yes, it is a theme file for Wordpress. I fixed these by changing to the following codes:
echo __("<li><span><!--:en-->Location: <!--:--><!--:ja-->場所:<!--:--></span>") . $event_location . '</li>';
echo '<div class="event-cancel-out"><p>' . __('<!--:en-->Sold Out<!--:--><!--:ja-->売り切れ<!--:-->') . '</p></div><!-- end .event-cancel-out -->';

Why does my translation not work & how can I fix it?

I'm struggling with a translation in the footer navigation. the translation for the navigation works fine but I can't figure out how to set the translation for text_1 & text_2. I would appreciate any help a lot!
This is my PHP for the language:
<?php
class l
{
public static function lang($name)
{
$l = array();
// Footer
$l['text_1'] = "Hello";
$l['text_2'] = "World";
return $l[$name];
}
public static function __callStatic($name, $arguments)
{
return self::lang($name);
}
}
?>
And this is what I try to translate (text_1 & text_2):
<?php
class footer_nav
{
public function get_footer_nav()
{
$lang = language::getLang();
if (isset($_GET['page']))
$page = $_GET['page'];
else
$page = 'home';
$ret = '
<a href="' . $lang . '/private" ';
if ($page == 'private')
$ret .= ('class="active"');
$ret .= '>' . l::confidence() . '</a>
<a href="' . $lang . '/rules" ';
if ($page == 'rules')
$ret .= ('class="active"');
$ret .= '>' . l::rules() . '</a>
<a href="' . $lang . '/reklama" ';
if ($page == 'reklama')
$ret .= ('class="active"');
$ret .= '>' . l::adv() . '</a>
<a href="' . $lang . '/contact" ';
if ($page == 'contact')
$ret .= ('class="active"');
$ret .= '>' . l::contacts() . '</a>
';
return $ret;
<div class="soc_box">
<p class="soc_box_txt">
' . l::text_1() . '<br />
' . l::text_2() . '
</p>
</div>
}
}
?>
You can take the divs out of the Php code like this:
?>
<div class="soc_box">
<p class="soc_box_txt">
' . l::text_1() . '<br />
' . l::text_2() . '
</p>
</div>
<?php
Just close php code with ?> add html code and start php code again with < ?php or:
echo '<div class="soc_box">';
echo '';
echo '';
echo '<p class="soc_box_txt">
\' . l::text_1() . \'<br />
\' . l::text_2() . \'
</p>';
echo ' </div>';

Categories