I created a shortcode to display social icons within the theme I am using (Divi). The social icons are contained in a PHP template called "social_icons.php".
This is the function I am using:
function social_icons_shortcode() {
$social_icons = get_template_part( 'includes/social_icons' );
echo $social_icons;
}
add_shortcode('social-icons', 'social_icons_shortcode');
Here is the the social_icons.php template:
<div id="custom-social-icons">
<?php if( get_field('facebook', 'option') ): ?>
<a class="icon facebook" href="<?php echo get_field( 'facebook', 'option' ) ?>" title="Follow us on Facebook"></a>
<?php endif; ?>
<?php if( get_field('twitter', 'option') ): ?>
<a class="icon twitter" href="<?php echo get_field( 'twitter', 'option' ) ?>" title="Follow us on Twitter"></a>
<?php endif; ?>
<?php if( get_field('instagram', 'option') ): ?>
<a class="icon instagram" href="<?php echo get_field( 'instagram', 'option' ) ?>" title="Follow us on Instagram"></a>
<?php endif; ?>
<?php if( get_field('youtube', 'option') ): ?>
<a class="icon youtube" href="<?php echo get_field( 'youtube', 'option' ) ?>" title="Follow us on YouTube"></a>
<?php endif; ?>
<?php if( get_field('linkedin', 'option') ): ?>
<a class="icon linkedin" href="<?php echo get_field( 'linkedin', 'option' ) ?>" title="Find us on Linkedin"></a>
<?php endif; ?>
</div>
The shortcode works fine when I want to show the social icons in the footer of the theme but when I try to put them into the body (eg: the contact page) they are displaying absolute at the upper left hand corner of the page. See Screenshot: https://share.getcloudapp.com/8LuJkODx
I cannot figure out why this is happening - is there something I am doing wrong with get_template_part()?
Ahh..I see what the problem is. You need to return the value, not echo.
function social_icons_shortcode() {
$social_icons = get_template_part( 'includes/social_icons' );
return $social_icons;
}
add_shortcode('social-icons', 'social_icons_shortcode');
The other thing that may happen because how get_template_part() works, you may need to use an ob_buffer.
function social_icons_shortcode() {
ob_start();
get_template_part( 'includes/social_icons' );
return ob_get_clean();
}
add_shortcode('social-icons', 'social_icons_shortcode');
Related
Here is a piece of my code.
<div class="thim-course-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="lpr_course <?php echo 'course-grid-' . $columns; ?>">
**<div class="course-item" onmouseover="hide_card('<?= get_the_ID()?>');" onmouseout="show_card('<?= get_the_ID()?>');">**
<div class="course-thumbnail" id="course-thumbnail-<?= get_the_ID()?>">
<a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
<?php echo thim_get_feature_image( get_post_thumbnail_id( get_the_ID() ), 'full', $thumb_w, $thumb_h, get_the_title() ); ?>
</a>
<?php do_action( 'thim_inner_thumbnail_course' ); ?>
<!-- <a class="course-readmore"
href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html__( 'Read More', 'eduma' ); ?></a> -->
</div>
<div class="thim-course-content" id="thim-course-content-<?= get_the_ID()?>">
<?php learn_press_courses_loop_item_instructor();
the_title( sprintf( '<h2 class="course-title">', esc_url( get_permalink() ) ), '</h2>' );
?>
<?php if ( class_exists( 'LP_Addon_Coming_Soon_Courses_Preload' ) && learn_press_is_coming_soon( get_the_ID() ) ): ?>
<div class="message message-warning learn-press-message coming-soon-message">
<?php esc_html_e( 'Coming soon', 'eduma' ) ?>
</div>
<?php else: ?>
<div class="course-meta">
<?php learn_press_courses_loop_item_instructor(); ?>
<?php thim_course_ratings(); ?>
<?php learn_press_courses_loop_item_students(); ?>
<?php thim_course_ratings_count(); ?>
<?php learn_press_courses_loop_item_price(); ?>
</div>
<?php learn_press_courses_loop_item_price(); ?>
<?php endif; ?>
<div class="course-readmore">
<?php esc_html_e( 'Read More', 'eduma' ); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
On the 4th line, I wanted to truncate the course maps on mouse over, so that all the part of the map at the bottom of the image disappears, only to reappear when there is no more flyover. The result obtained is different from what I wanted.
I put the link to the site to see: www.formatine.com
And here is the JS part that I added as well.
function hide_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'none';
document.getElementById('course-thumbnail-'+id).innerHTML = "<?= wp_oembed_get( $media_intro ) ?>";
}
function show_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'block';
document.getElementById('course-thumbnail-'+id).style.display = 'block';
}
Do you have an idea for me please? Thank you.
Don't use "display: none" because once it has it, the element "disappears".
It is better for you, to then, if you want to include a video instead of the card, for example, do it by having both, one behind the other by default, if you "mouseover" display the code INSIDE of one, and on "mouseout", display the other.
<div class="mycard">
<div class="myinfoforthevideo"></div>
<div class="myvideo"></div>
</div>
You controll the events on mycard class, and hide myinfoforthevideo by default, on "mouseover", hide it and show then myvideo, and on "mouseout" hide myvideo and show myinfoforthevideo
You're hidding everything so now since its a width: 0/height: 0 let's say, you don't have any place to do the mouseover now.
Extra:
You can try flip cards as another option, like this:
https://codepen.io/Aoyue/pen/pLJqgE
I don't have clickable header on my website. I want redirect to home page when I click on header. I don't know how the code should look to make it work.
This is my page-header.php code:
<div class="entry-header">
<div class="cv-outer">
<div class="cv-inner">
<div class="header-logo">
<?php
if ( has_custom_logo() ) :
$custom_logo_id = get_theme_mod( 'custom_logo' );
$custom_logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr( bloginfo('name') ); ?>" class="logo-img">
<img src="<?php echo esc_url( $custom_logo[0] ); ?>" alt="<?php esc_attr( bloginfo('name') ); ?>">
</a>
<?php else : ?>
<?php echo bloginfo( 'title' ); ?>
<?php endif; ?>
<?php if ( display_header_text() ) : ?>
<br>
<p class="site-description"><?php echo bloginfo( 'description' ); ?></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
I think I should add somethink here but I don't know PHP enough:
if ( has_custom_logo() ) :
$custom_logo_id = get_theme_mod( 'custom_logo' );
$custom_logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr( bloginfo('name') ); ?>" class="logo-img">
<img src="<?php echo esc_url( $custom_logo[0] ); ?>" alt="<?php esc_attr( bloginfo('name') ); ?>">
</a>
<?php else : ?>
<?php echo bloginfo( 'title' ); ?>
<?php endif; ?>
<?php if ( display_header_text() ) : ?>
<br>
<p class="site-description"><?php echo bloginfo( 'description' ); ?></p>
<?php endif; ?>
In additional I show you source of website in browser:
browser website source
All advice will be invaluable!
It looks like the title is empty.
In the else clause, if there is no custom logo, then a link will be displayed inside with text. The link is there, but it is not clickable because there is no text inside the link.
Can you check if bloginfo( 'title' ) is non-empty?
Another workaround would be to add a default picture that you know exists inside the link div, instead of text.
You just keep all header div in an Anchor element. Like below code
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
<div class="cv-inner">
<div class="header-logo">
</div>
</div>
</a>
I personally would put the PHP code in the definition for CV-Outer div.
<?PHP
if (has_custom_logo()) {
echo "<div class='cv-outer clickHeader'>" + PHP_EOL;
} else {
echo "<div class='cv-outer'>" + PHP_EOL;
}
?>
Then, just add an onclick handler to your javascript for the clickHeader class to redirect to the proper URL.
If you need to keep the custom logo from the PHP code, just leave it there, delete the bit that has the URL.
Basically, the problem is that the hyperlink isn't clickable because it has no size. Instead of messing with CSS to make it fit...I'd just remove it and use JS for the clickhandler...
Full HTML Code:
<div class="entry-header">
<?PHP
if (has_custom_logo()) {
echo "<div class='cv-outer clickHeader'>" + PHP_EOL;
} else {
echo "<div class='cv-outer'>" + PHP_EOL;
}
?>
<div class="cv-inner">
<div class="header-logo">
</div>
</div>
</div>
Sample Javascript:
<script>
window.onload = function() {
var headers = document.getElementsByTagName('clickHeader');
for(var i = 0; i < headers.length; i++) {
var header = headers[i];
header.onclick = function() {
document.location.href="/";
}
}
}
</script>
I am on Wordpress and I can easily add a plugin, but that increases load time, looks common and old.
I am using the Brook theme, which a minimal theme. (http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/)
If you notice, only end at the blog I have my sharing options, Such as Facebook, Linkedin, Twitter.
Can I enable this in the Sidebar widget? I contacted my theme author and they said to me,
"Our social-sharing links are built in brook/share_block.php. You
could try creating a new custom widget, and use the code from
share_block.php. Alternatively, you could use a Text Widget, and input
directly html code for sharing. By using the markup and classes as we
did, you should be able to get the same style."
Here's my that php file. I tried various methods but it did not work. Guess everything is wrong.
Can you all help?
<?php
$theme_settings = brook_theme_settings();
if( has_post_thumbnail() ){
$share_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'xxl' );
$share_image = $share_image[0];
$share_image_portrait = wp_get_attachment_image_src( get_post_thumbnail_id(), 'portrait-m' );
$share_image_portrait = $share_image_portrait[0];
}else{
$share_image = '';
$share_image_portrait = '';
}
$share_excerpt = strip_tags( get_the_excerpt(), '<b><i><strong><a>' );
?>
<div class="social-nav social-nav--titles">
<ul class="social-nav__items">
<?php if( $theme_settings['sharing_email'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Email', 'brook' ); ?>" class="social-nav__link js-skip-ajax" href="mailto:?subject=<?php echo ( rawurlencode( get_the_title() ) ); ?>&body=<?php echo ( rawurlencode ( $share_excerpt . ' ' . get_the_permalink() ) ); ?>">
<?php _e( 'Email', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_facebook'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Facebook', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Facebook', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_twitter'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Twitter', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://twitter.com/intent/tweet?text=<?php echo( rawurlencode( get_the_title() ) ); ?>&url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Twitter', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_pinterest'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Pinterest', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&media=<?php echo ( rawurlencode( $share_image_portrait ) ); ?>&description=<?php echo( rawurlencode( get_the_title() ) ); ?>">
<?php _e( 'Pinterest', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_google'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Google+', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="https://plus.google.com/share?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Google+', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_linkedin'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'LinkedIn', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&title=<?php echo( rawurlencode( get_the_title() ) ); ?>&summary=<?php echo ( rawurlencode ( $share_excerpt ) );?>&source=<?php echo ( rawurlencode( get_bloginfo('name') ) );?>">
<?php _e( 'LinkedIn', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
</ul>
</div>
Well What I suggest you which is the easiest solution is first install a plugin from this link https://wordpress.org/plugins/php-code-widget/ It ia a plugin when you activate it, it creates a widget in which you can put your all php code from your required file. As far as the styling is concerned you can add the relevant styling to main css file of your Brook theme. I hope it helps....
Try to social share plugin and put shortcode.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm trying to create a page for WordPress "category.php" from the code in this tutorial: http://scratch99.com/wordpress/wp-seo/siloing/
My current theme (Sociallyviral by Themeforest) there is no page "category.php," so I created one and added the code below:
Author's Note:
"The code should look something like the below. Note, you can’t just use this code exactly – it needs to fit in with your theme so that the classes of wrapping divs, etc match the rest of your theme and the style is picked up."
// work out category id, then see if there are any subcategories
$main_cat_ID = get_query_var( 'cat' );
$subcats = get_categories( array( 'parent' => $main_cat_ID, 'hide_empty' => 0 ) );
// if it is page 1
if ( $paged < 2 ) :
// show the category description
echo category_description();
// if there are subcategories, loop through and show them
if ( count( $categories ) > 0 ) :
foreach ( $subcats as $category ) : ?>
<div class="subcategory">
<h2><a class="subcategory-link" href="<?php echo get_category_link( $category->term_id ); ?>">
<?php echo $category->name; ?></a></h2>
<?php echo wpautop( $category->description ); ?>
</div>
<?php
endforeach;
endif;
// get sticky posts and show them if they exist
$args = array( 'category__in' => $main_cat_ID, 'include' => get_option( 'sticky_posts' ) );
$myposts = get_posts( $args );
if ( count( $myposts ) > 0 ) :
foreach ( $myposts as $value ) : ?>
<div class="sticky">
<h3>
<a href="<?php echo get_permalink( $value->ID ); ?>" rel="bookmark"
title="<?php echo $value->post_title; ?>"><?php echo $value->post_title; ?></a>
</h3>
<div class="entry-content">
<?php
// if there is an excerpt, use it, otherwise roll our own (get_the_excerpt won't work outside the loop)
if ( $value->post_excerpt ) :
echo wpautop( $value->post_excerpt );
else :
$sjc_excerpt = explode( '<!--more-->', $value->post_content );
if ( count( $sjc_excerpt ) >= 2 ) :
echo wpautop( strip_tags( $sjc_excerpt[0] ) );
else :
echo wpautop( implode ( ' ', array_slice( explode( ' ', strip_tags( $sjc_excerpt[0] ) ), 0, 45 ) ) . ' ...' );
endif;
endif; ?>
</div>
</div>
<?php
endforeach;
endif;
// pages 2 and onwards don't worry about cat desc or stickies, but link to main cat page
else : ?>
<p>For an introduction to this topic and our latest articles, please see the main
<?php single_cat_title(); ?> page.</p>
<?php
endif;
// if we have any posts in the main loop (no stickies there)
if ( have_posts() ) : ?>
<ul class="other-posts">
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
// you need to replace this with whatever your theme uses!
sjc_content_nav( 'nav-below' );
// if no posts, and also no stickies and no categories, go with no results
elseif ( count( $myposts ) == 0 && count( $subcats ) == 0 ) :
get_template_part( 'no-results', 'archive' );
endif;
If necessary, below my theme file "archive.php"
<?php $mts_options = get_option(MTS_THEME_NAME); ?>
<?php get_header(); ?>
<div id="page">
<div id="content_box">
<h1 class="postsby">
<?php if (is_category()) { ?>
<span><?php single_cat_title(); ?><?php _e(" Archive", "mythemeshop"); ?></span>
<?php } elseif (is_tag()) { ?>
<span><?php single_tag_title(); ?><?php _e(" Archive", "mythemeshop"); ?></span>
<?php } elseif (is_author()) { ?>
<span><?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); echo $curauth->nickname; _e(" Archive", "mythemeshop"); ?></span>
<?php } elseif (is_day()) { ?>
<span><?php _e("Daily Archive:", "mythemeshop"); ?></span> <?php the_time('l, F j, Y'); ?>
<?php } elseif (is_month()) { ?>
<span><?php _e("Monthly Archive:", "mythemeshop"); ?>:</span> <?php the_time('F Y'); ?>
<?php } elseif (is_year()) { ?>
<span><?php _e("Yearly Archive:", "mythemeshop"); ?>:</span> <?php the_time('Y'); ?>
<?php } ?>
</h1>
<?php $j = 1; if (have_posts()) : while (have_posts()) : the_post(); $featured = get_post_meta($post->ID, 'mts_featured', true); ?>
<article class="latestPost excerpt<?php echo (($j+2) % 3 == 0) ? ' first' : ''; ?><?php echo ($j % 3 == 0) ? ' last' : ''; ?>" itemscope itemtype="http://schema.org/BlogPosting">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail">
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail('featured',array('title' => '')); echo '</div>'; ?>
<?php if (function_exists('wp_review_show_total')) wp_review_show_total(true, 'latestPost-review-wrapper'); ?>
<?php if ($featured) : ?><div class="post-label"><i class="fa fa-star"></i> <span><?php _e('Featured','mythemeshop'); ?></span></div><?php endif; ?>
</a>
<header>
<h2 class="title front-view-title"><?php the_title(); ?></h2>
<?php if ( ! empty( $mts_options["mts_home_headline_meta"] ) ) { ?>
<div class="post-info">
<?php if( ! empty( $mts_options["mts_home_headline_meta_info"]['date']) ) { ?>
<span class="thetime updated"><i class="fa fa-calendar"></i> <span itemprop="datePublished"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . __(' ago','mythemeshop'); ?></span></span>
<?php } ?>
<?php if( ! empty( $mts_options["mts_home_headline_meta_info"]['category']) ) { ?>
<span class="thecategory"><i class="fa fa-tags"></i> <?php mts_the_category(', ') ?></span>
<?php } ?>
</div>
<?php } ?>
</header>
</article><!--.post excerpt-->
<?php $j++; endwhile; endif; ?>
<!--Start Pagination-->
<?php if (isset($mts_options['mts_pagenavigation_type']) && $mts_options['mts_pagenavigation_type'] == '1' ) { ?>
<?php mts_pagination(); ?>
<?php } else { ?>
<div class="pagination pagination-previous-next">
<ul>
<li class="nav-previous"><?php next_posts_link( '<i class="fa fa-angle-left"></i> '. __( 'Previous', 'mythemeshop' ) ); ?></li>
<li class="nav-next"><?php previous_posts_link( __( 'Next', 'mythemeshop' ).' <i class="fa fa-angle-right"></i>' ); ?></li>
</ul>
</div>
<?php } ?>
<!--End Pagination-->
</div>
<?php get_footer(); ?>
I get this error when i try to open the category page:
"Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in /wp-content/themes/sociallyviral/category.php on line 20"
This syntax error, are solved!
Thank you all!
Best regards!
You are missing the <?php Tag at the beginning of your file.
Without it, the first bit of code, the parser will parse the following code as php:
echo get_category_link( $category->term_id );
echo $category->name;
echo wpautop( $category->description );
endforeach;
endif;
as you can see, the first thing to reach (beside the three echo's) is endforeach;and this is where your parser throws an error.
The authors note said the following: "...it needs to fit in with your theme so that the classes of wrapping divs, etc match the rest of your theme and the style is picked up."
This means, that you need to provide the <div>'s in your code with class and style addributes, according to your and your templates needs. In detail, you are meant to apply the classes used by your template, to apply the desired layout. You should have some form of reference of the classes your template uses (probably something like this). Where you can have a look at which classes to use.
This is what the reference of bootstrap looks like - just to give you some idea of what you are after.
Put a php tag at the beginning of your code
<?php // show the category description
echo category_description();
// if there are subcategories, loop through and show them
if ( count( $categories ) > 0 ) :
foreach ( $subcats as $category ) : ?>
<div class="subcategory">
<h2><a class="subcategory-link" href="<?php echo get_category_link( $category->term_id ); ?>">
<?php echo $category->name; ?></a></h2>
<?php echo wpautop( $category->description ); ?>
</div>
<?php
endforeach;
endif;
// get sticky posts and show them if they exist
$args = array( 'category__in' => $main_cat_ID, 'include' => get_option( 'sticky_posts' ) );
$myposts = get_posts( $args );
if ( count( $myposts ) > 0 ) :
foreach ( $myposts as $value ) : ?>
<div class="sticky">
<h3>
<a href="<?php echo get_permalink( $value->ID ); ?>" rel="bookmark"
title="<?php echo $value->post_title; ?>"><?php echo $value->post_title; ?></a>
</h3>
<div class="entry-content">
<?php
// if there is an excerpt, use it, otherwise roll our own (get_the_excerpt won't work outside the loop)
if ( $value->post_excerpt ) :
echo wpautop( $value->post_excerpt );
else :
$sjc_excerpt = explode( '<!--more-->', $value->post_content );
if ( count( $sjc_excerpt ) >= 2 ) :
echo wpautop( strip_tags( $sjc_excerpt[0] ) );
else :
echo wpautop( implode ( ' ', array_slice( explode( ' ', strip_tags( $sjc_excerpt[0] ) ), 0, 45 ) ) . ' ...' );
endif;
endif; ?>
</div>
</div>
<?php
endforeach;
endif;
// pages 2 and onwards don't worry about cat desc or stickies, but link to main cat page
else : ?>
<p>For an introduction to this topic and our latest articles, please see the main
<?php single_cat_title(); ?> page.</p>
<ul class="other-posts">
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
// you need to replace this with whatever your theme uses!
sjc_content_nav( 'nav-below' );
// if no posts, and also no stickies and no categories, go with no results
elseif ( count( $myposts ) == 0 && count( $subcats ) == 0 ) :
get_template_part( 'no-results', 'archive' );
endif;
your problem will solved.
Here is my code:
add_filter("the_content", "plugin_myContentFilter", "tie_excerpt_home_length");
function plugin_myContentFilter($content)
{
$content = preg_replace("/<img[^>]+\>/i", "(kép)", $content);
// Take the existing content and return a subset of it
return substr($content, 0, 300);
}
I would like to see this function work only the homepage. But unfortunatly this code is working everywhere (posts, pages), and do not let to display the whole content.
Here is the code which should be reflected in the content on the homepage:
<li <?php tie_post_class('first-news'); ?>>
<div class="inner-content">
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php tie_thumb( 'tie-medium' ); ?>
<span class="overlay-icon"></span>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<h2 class="post-box-title"><?php the_title(); ?></h2>
<?php get_template_part( 'includes/boxes-meta' ); ?>
<div class="entry">
<?php if($_eventcat) the_content(); else tie_excerpt_home() ?>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Tovább >', 'tie' ) ?></a>
</div>
</div>
</li>
Add the conditional for checking the home page. is_home() checks if it's the blog post index, is_front_page() checks if it's the frontpage (blog post or static page);
if ( is_home() || is_front_page() ) {
add_filter("the_content", "plugin_myContentFilter", "tie_excerpt_home_length");
}
function plugin_myContentFilter($content)
{
$content = preg_replace("/<img[^>]+\>/i", "(kép)", $content);
// Take the existing content and return a subset of it
return substr($content, 0, 300);
}