Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for featured image display/import #5

Open
tw2113 opened this issue Jun 9, 2016 · 34 comments
Open

Add support for featured image display/import #5

tw2113 opened this issue Jun 9, 2016 · 34 comments

Comments

@tw2113
Copy link
Member

tw2113 commented Jun 9, 2016

https://wordpress.org/support/topic/1-issue-and-1-suggestion?replies=1

See #5 (comment) regarding how plugin currently handles aggregated featured images.

@grapparubinsky
Copy link

Hello,
I have the same problem at the moment...

Thanks

@LarkRiseMedia
Copy link

Any news on completion date?

@tw2113
Copy link
Member Author

tw2113 commented Aug 15, 2016

Nope, not at the moment.

@streiten
Copy link

same here... any ideas for workarounds anyone ?

@streiten
Copy link

streiten commented Oct 3, 2016

works for me now. make sure to use get_the_post_thumbnail() to retrieve it. looks like the_post_thumbnail() and has_post_thumbnail() don't work here. also had to hack in/fork for different thumb sizes as my themes thumb sizes and 'full' didn't work...

@tw2113
Copy link
Member Author

tw2113 commented Oct 3, 2016

@streiten what changes did you make and to which file?

@streiten
Copy link

streiten commented Oct 4, 2016

@tw2113 actually after revising my code i didn't change anything in the plugin code. in my theme's function im hooking in the sitewide_tags_thumb_size to define which thumbnail size markup should be stored (and later on retrieved) with the duplcated post. if you have a look here and in the post_meta table for key "thumbnail_etc" and similiar this gets more clear.

// define thumbsizes for aggregating blog posts  
function sitewide_tags_thumb_size_cb( $array ) {  
    return array('full');  
}
add_filter( 'sitewide_tags_thumb_size', 'sitewide_tags_thumb_size_cb', 10, 3 );

for my theme itself i had to do the follwing changes to make it work:

<?php if ( has_post_thumbnail() ) : ?>
  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>

to

<?php if ( !empty(get_the_post_thumbnail($post->ID,'full'))) : ?>
  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <?php echo get_the_post_thumbnail($post->ID,'full'); ?>

@tw2113
Copy link
Member Author

tw2113 commented Oct 4, 2016

Gotcha. Thanks for that explanation. :)

@boeta2016
Copy link

I have the same problem but unfortunately don't know how to change code. Is there an indication when this will be fixed in the plugin. I appreciate your great work!

@tw2113
Copy link
Member Author

tw2113 commented Oct 7, 2016

No timeframe I'm aware of, we're not actively working on the plugin as of late.

@PJSAnd
Copy link

PJSAnd commented Oct 14, 2016

Hello,
I've also started using this plugin and am having the same problem with featured image.

Streiten, as well as changing the function file, could you tell me which file in the theme you changed this code?

for my theme itself i had to do the follwing changes to make it work:

`

` to ` ID,'full'))) : ?> ID,'full'); ?> `

@streiten
Copy link

@PJSAnd totally depends on the theme you are using and how its template files are structured. could also be nested in a function. for twentysixteen this would be twentysixteen_post_thumbnail() in inc/template-tags.php for example.

@PJSAnd
Copy link

PJSAnd commented Oct 14, 2016

@streiten thanks. OK, I'm no techie and I'm not using twentysixteen...are you able to tell which file to edit from viewing the page via firefox? My test page is at nisekotravel.com - any chance you could have a look

@streiten
Copy link

@PJSAnd no, you can not really find it from looking at the website/markup. looks like a custom theme - contact the theme developer. also the conversation getting a bit offtopic now... :-)

@tw2113
Copy link
Member Author

tw2113 commented Oct 14, 2016

I do believe the topic has swayed away from the original issue. I believe when I opened this, it was more about getting the featured image data included and into the aggregated data, and less about display issues on the frontend.

@boeta2016
Copy link

boeta2016 commented Oct 19, 2016

I have located the code which I think I should edit to show the feature image data included. Below is the code and I have tried to edit it but without any success. I would appreciate it a LOT if you can give me some help here:

public function html($args = array()) {
        global $post;
        extract($args = is_array($args) ? $args : array());
        $size = !empty($this->options['size']) ? $this->options['size'] : 'full';
        $alignment = !empty($this->options['alignment']) ? ($this->options['alignment'] == 'left' ?
            'alignleft' : ($this->options['alignment'] == 'right' ?
            'alignright' :
            'aligncenter')) : false;
        $image = get_the_post_thumbnail($post->ID, $size, array_filter(array(
            'itemprop' => !empty($schema) ? 'image' : false,
            'class' => !empty($alignment) ? $alignment : false)));
        if (empty($image)) return;
        $html = str_repeat("\t", !empty($depth) ? $depth : 0).
            (!isset($this->options['link']) ?
            '<a class="featured_image_link" href="'. get_permalink(). '">' : '').
            $image.
            (!isset($this->options['link']) ?
            '</a>' : '');
        if (!empty($return))
            return "$html\n";
        else
            echo "$html\n";
}

@tw2113
Copy link
Member Author

tw2113 commented Oct 19, 2016

@boeta2016 I have no idea what that's referring to, as it's not part of this plugin, from what I can see.

I also really think the discussion here is veering away from the original intent for the issue, which is to make sure featured images for posts are sync'd into the aggregated site. Nothing to do with displaying anything on the frontend in a given theme.

@boeta2016
Copy link

I do not agree with the discussion veering away. I had a look at what @streiten did where he changed the code in his theme. So I searched in my theme to what I think I need to change to make sure featured images for posts are sync'd into the aggregated site.

The code that I gave is what I need to change in my theme to get that images into the post.

@tw2113
Copy link
Member Author

tw2113 commented Oct 19, 2016

Which is why I feel the discussion has veered away from the originally opened issue topic.

The issue is about ensuring that the featured image is part of the data/content that is sync'd into the aggregated site install. However it's not about the display of said content in a theme file.

Regarding your code above, I'm not sure what exactly is not working. What's the resulting HTML output that you're seeing, compared to what you're expecting? This part is also best fit for https://wordpress.org/support/plugin/wds-multisite-aggregate instead of here in GitHub.

@boeta2016
Copy link

The post that are aggregated to the main site are missing the featured image. When I open the post in the wordpress editor the featured image from the original post is not there.

There is nothing wrong with my theme because if I update the post and manually add the featured image to the aggregated post it shows.

I cannot however manually edit each post that aggregates.

I need the featured image to be included into the aggregated post.

@tw2113
Copy link
Member Author

tw2113 commented Oct 19, 2016

Which is what this open issue IS about. Making sure they get imported/migrated over.

@PJSAnd
Copy link

PJSAnd commented Nov 20, 2016

OK - so HOW DO I MAKE SURE THE FEATURED IMAGES ARE MIGRATED OVER TO THE MAIN/AGGREGATED BLOG?

Surely this IS on topic :)

@tw2113
Copy link
Member Author

tw2113 commented Nov 20, 2016

I don't know why it may or may not be working at the moment. I haven't had a chance to sit down to thoroughly check and test.

From looking through the code only, this spot should be covering it, https://github.com/WebDevStudios/WDS-Multisite-Aggregate/blob/master/wds-multisite-aggregate.php#L298-L304 as the featured image to use is stored as a meta key of _thumbnail_id

@PJSAnd
Copy link

PJSAnd commented Nov 21, 2016

Sure, OK. When you say 'this spot should be covering it', can you make a suggestion as to what I should do to this bit of code to get the plugin working properly?

I know this is s free plugin, which is great, but surely it can't be that much of a big deal to get feature images carried through along with the text to the main blog....surely!!!

@tw2113
Copy link
Member Author

tw2113 commented Nov 21, 2016

Well, my first question would be have you confirmed it's not? or are you just going based on the issue here existing? It could be an invalid ticket, and the feature working as a whole.

Perhaps the meta fields is migrating properly, but values are mismatching or not finding an attachment of the proper ID, meaning there's a different bug.

@PJSAnd
Copy link

PJSAnd commented Nov 21, 2016

Well, tw2113 what's your opinion? Are you saying that this is an invalid ticket and a waste of everyone's time?

Back to the issue: It doesn't seem to be working on any theme that I've used including the standard 2014/15/16. This would suggest, I would guess, that there is a compatibility issue with the plugin and wordpress. So yes a mismatch could be the problem. But I'm no techie and would not know where to correct this.

Look, if you can help...great. But if you have no intention of helping solve this issue (which I suspect looking at the comments above) then please just let us know rather than stringing us along with vague comments like above. That would save everyone's time.

@tw2113
Copy link
Member Author

tw2113 commented Nov 21, 2016

My opinion is that testing is needed to confirm. The more the better, from anyone willing.

I'm not worried about the frontend display, because that's dependent on the theme being used by the site owner. I'm concerned about if the aggregated version has the correct thumb displayed for each post in the WP Admin. It's not that I can't or won't help, but time is the proverbial issue for everyone. Based on the code I highlighted above, it SHOULD be covered already. We had one person report issue. I'll try to carve out some time soon to test myself. It just may not be today.

@tw2113
Copy link
Member Author

tw2113 commented Nov 23, 2016

So, I found myself with some time tonight, and in conclusion, I do have to apologize on a number of levels. In large part, because I'm not one of the original devs of the plugin, but still generally handle frontline support for it. So I have my own holes of knowledge around the plugin as a whole.

From my testing and checking, it does NOT indeed migrate the _thumbnail_id field, and I have to believe a lot of that is because it would require also importing into the aggregated website, due to how featured images and attachment IDs work. What I did see and find with my tests is that there are meta fields with meta keys of "thumbnail_html" and "thumbnail_html_thumbnail" by default. In those are HTML image tags storing the URL to the appropriate file on the server. There are filters to add more image sizes as well for the sync. Standard get_post_meta() calls with the appropriate ID and meta key will fetch those fine. It's not the most "ideal" way to handle featured images, but it would, in fact, work. Other metadata items I'm seeing attached include blogid and permalink which correspond to the blog ID the data was fetched from, as well as the original post permalink.

That said, to satisfy the original intent of this issue, would require amending enough to set both the _thumbnail_id parameter as well as make the image itself get migrated into the aggregated new site.

@PJSAnd
Copy link

PJSAnd commented Nov 26, 2016 via email

@tw2113
Copy link
Member Author

tw2113 commented Nov 26, 2016

If you're wanting to have the aggregated post have the featured image field set specifically, you're going to need someone willing to modify the plugin to handle that.

You could also just use the meta fields I pointed out that store image tags of the aggregated featured image, as that would get you something to use. It appears to be the solution to the topic our devs originally went with. Provide HTML image tags, stored as post meta, instead of import every image involved into the specified aggregate site. If I recall right, there's a filter that can be used to set more image sizes to be included.

I'm actually agreeing with the solution provided in this case, and feel we can close this GitHub ticket as a non-issue.

@mguenscher
Copy link

mguenscher commented Mar 14, 2017

Please I'm facing with this problem, I have 1 week try to solve it and test different Wordpress themes, so please can you help me to solve it with Ipin theme?

My single.php file

<?php get_header(); ?>

<div class="container">
	<div class="row">
		<div class="col-sm-9">
			<div class="row">
				<div id="double-left-column" class="col-sm-8">
					<?php while (have_posts()) : the_post(); ?>
					<div id="post-<?php the_ID(); ?>" <?php post_class('post-wrapper'); ?>>
						<div class="h1-wrapper">
							<h1><?php the_title(); ?></h1>
						</div>
						
						<div class="post-meta-top">
							<div class="pull-right"><a href="#navigation"><?php comments_number(__('0 Comments','ipin'), __('1 Comment', 'ipin'), __('% Comments',' ipin'));?></a><?php edit_post_link(__('Edit', 'ipin'), ' | '); ?></div>
							<div class="pull-left"><?php echo ipin_human_time_diff(get_post_time('U', true)) . ' / ';the_author(); ?></div>
						</div>		

						<div class="post-content">
							<?php
							if (has_post_thumbnail()) {
                                                              the_post_thumbnail();
								
							}
							the_content();
							wp_link_pages( array( 'before' => '<p><strong>' . __('Pages:', 'ipin') . '</strong>', 'after' => '</p>' ) );							
							?>
							
							<div class="clearfix"></div>
							
							<div class="post-meta-category-tag">
								<?php _e('Categories', 'ipin'); ?>: <?php the_category(', '); ?> 
								<?php the_tags(__('Tags: ', 'ipin'), ', '); ?>
							</div>
							
							<div id="navigation">
								<ul class="pager">
									<li class="previous"><?php previous_post_link('%link', '&laquo; %title'); ?></li>
									<li class="next"><?php next_post_link('%link', '%title &raquo;'); ?></li>
								</ul>
							</div>
						</div>
						
						<div class="post-comments">
							<div class="post-comments-wrapper">
								<?php comments_template(); ?>
							</div>
						</div>
						
					</div>
					<?php endwhile; ?>
				</div>
				
				<div id="single-right-column" class="col-sm-4">
					<?php get_sidebar('left'); ?>
				</div>
			</div>
		</div>
		
		<div class="col-sm-3">
			<?php get_sidebar('right'); ?>
		</div>
	</div>
</div>

<?php get_footer(); ?>

And my index page file

<?php get_header(); ?>

<div class="container-fluid">
	<?php if (have_posts()) : ?>
		<div id="ajax-loader-masonry" class="ajax-loader"></div>
		<div id="masonry">
	<?php while (have_posts()) : the_post(); ?>
		<div id="post-<?php the_ID(); ?>" <?php post_class('thumb'); ?>>
			<div class="thumb-holder">
				<div class="masonry-actionbar">
					<button class="btn btn-info btn-sm" onclick="window.location.href='<?php the_permalink(); ?>/#respond'"><i class="fa fa-comment"></i> <?php _e('Comment', 'ipin'); ?></button>
					<button class="btn btn-info btn-sm" onclick="window.location.href='<?php the_permalink(); ?>'"><?php _e('View', 'ipin'); ?> <i class="fa fa-arrow-right"></i></button>
				</div>
				<a href="<?php the_permalink(); ?>">
					<?php
					$imgwidth = '';
					$imgheight = '';
					if (has_post_thumbnail()) {
						$imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium');
						$imgwidth = $imgsrc[1];
						$imgheight = $imgsrc[2];
						$imgsrc = $imgsrc[0];
					} elseif ($postimages = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=0")) {
						foreach($postimages as $postimage) {
							$imgsrc = wp_get_attachment_image_src($postimage->ID, 'medium');
							$imgwidth = $imgsrc[1];
							$imgheight = $imgsrc[2];
							$imgsrc = $imgsrc[0];
						}
					} elseif (preg_match('/<img [^>]*src=["|\']([^"|\']+)/i', get_the_content(), $match) != FALSE) {
						$imgsrc = $match[1];
					} else {
						$imgsrc = get_template_directory_uri() . '/img/blank.gif';
					}
					?>
					<img src="<?php echo $imgsrc; $imgsrc = ''; ?>" alt="<?php the_title_attribute(); ?>"  style="<?php if ($imgwidth != '') { ?>width:200px;height:<?php echo round(200/$imgwidth*$imgheight); ?>px;<?php } else { ?>width:200px;height:200px;<?php } ?>" />

					<div class="thumbtitle"><?php the_title(); ?></div>
				</a>
			</div>
			
			<div class="masonry-meta<?php $show_avatars = get_option('show_avatars'); $comments_number = get_comments_number(); if ($comments_number == 0 && $show_avatars == '0') { echo ' text-center'; } ?>">
				<?php if ($show_avatars == '1') { ?>
				<div class="masonry-meta-avatar"><?php echo get_avatar(get_the_author_meta('user_email') , '25'); ?></div>
				<div class="masonry-meta-comment">
				<?php } ?>
					<span class="masonry-meta-author"><?php echo get_the_author_meta('display_name') ?></span> <?php _e('onto', 'ipin'); ?> <span class="masonry-meta-content"><?php the_category(', '); ?></span>
				<?php if ($show_avatars == '1') { ?>
				</div>
				<?php } ?>
			</div>
				
			<?php
			if ('0' != $frontpage_comments_number = of_get_option('frontpage_comments_number')) {
				$args = array(
					'number' => $frontpage_comments_number,
					'post_id' => $post->ID,
					'status' => 'approve'
				);
				$comments = get_comments($args);
				foreach($comments as $comment) {
				?>
				<div class="masonry-meta">
					<?php if ($show_avatars == '1') { ?>
					<div class="masonry-meta-avatar"><?php echo get_avatar( $comment->comment_author_email , '25'); ?></div>
					<div class="masonry-meta-comment">
					<?php } ?>
						<span class="masonry-meta-author"><?php echo $comment->comment_author; ?></span> 
						<?php echo $comment->comment_content; ?>
					<?php if ($show_avatars == '1') { ?>
					</div>
					<?php } ?>
				</div>
				<?php 
				}
				if ($comments_number > $frontpage_comments_number) {
				?>
				<div class="masonry-meta text-center">
					<span class="masonry-meta-author">
					<a href="<?php the_permalink() ?>/#navigation" title="<?php _e('View all', 'ipin'); ?> <?php echo $comments_number; ?> <?php _e('comments', 'ipin') ?>"><?php _e('View all', 'ipin'); ?> <?php echo $comments_number; ?> <?php _e('comments', 'ipin') ?></a>
					</span>
				</div>
			<?php } 
			}	?>
		</div>
	<?php endwhile; ?>
		</div> <?php //end div#masonry ?>
	<?php else : ?>
		<div class="row">
			<div class="hidden-xs col-sm-3"></div>
	
			<div class="col-sx-12 col-sm-6">
				<div class="post-wrapper">
					<div class="h1-wrapper">
						<h1><?php _e( 'No Items Found', 'ipin' ); ?></h1>
					</div>		
	
					<div class="post-content text-center">
					<p><?php _e('Perhaps searching will help.', 'ipin'); ?></p>
					<?php get_search_form(); ?>
					</div>
				</div>
			</div>
		
			<div class="hidden-xs col-sm-3"></div>
		</div>
		<?php endif; ?>
	

	<div id="navigation">
		<ul class="pager">
			<li id="navigation-next"><?php next_posts_link(__('&laquo; Previous', 'ipin')) ?></li>
			<li id="navigation-previous"><?php previous_posts_link(__('Next &raquo;', 'ipin')) ?></li>
		</ul>
	</div>
</div>

<?php get_footer(); ?>

and my function.php file

<?php
load_theme_textdomain( 'ipin', get_template_directory() . '/languages' );

if ( !function_exists( 'optionsframework_init' ) ) {
	define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
	require_once dirname( __FILE__ ) . '/inc/options-framework.php';
}

add_editor_style();

if (!isset($content_width))
	$content_width = 505;

register_nav_menus(array('top_nav' => __('Top Navigation', 'ipin')));

register_sidebar(array('name' => 'sidebar-left', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h4>', 'after_title' => '</h4>'));
register_sidebar(array('name' => 'sidebar-right', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h4>', 'after_title' => '</h4>'));

add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
add_theme_support('custom-background', array(
	'default-color' => 'f2f2f2',
));

function ipin_scripts() {
	wp_enqueue_script('ipin_bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), null, true);
	wp_enqueue_script('ipin_custom', get_template_directory_uri() . '/js/ipin.custom.js', array('jquery'), null, true);

	if (is_singular() && comments_open() && get_option( 'thread_comments' )) {
		wp_enqueue_script('comment-reply');
	}
		
	if (!is_singular()) {
		wp_enqueue_script('ipin_masonry', get_template_directory_uri() . '/js/jquery.masonry.min.js', array('jquery'), null, false);
		wp_enqueue_script('ipin_imagesloaded', get_template_directory_uri() . '/js/jquery.imagesloaded.min.js', array('jquery'), null, false);
		wp_enqueue_script('ipin_infinitescroll', get_template_directory_uri() . '/js/jquery.infinitescroll.min.js', array('jquery'), null, false);
	}

	$translation_array = array(
		'__allitemsloaded' => __('All items loaded', 'ipin'),
		'stylesheet_directory_uri' => get_template_directory_uri()
	);
	wp_localize_script('ipin_custom', 'obj_ipin', $translation_array);
}
add_action('wp_enqueue_scripts', 'ipin_scripts');


/**
 * From Roots Theme http://rootstheme.com
 * Cleaner walker for wp_nav_menu()
 *
 * Walker_Nav_Menu (WordPress default) example output:
 *   <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li>
 *   <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l
 *
 * Roots_Nav_Walker example output:
 *   <li class="menu-home"><a href="/">Home</a></li>
 *   <li class="menu-sample-page"><a href="/sample-page/">Sample Page</a></li>
 */
function is_element_empty($element) {
  $element = trim($element);
  return empty($element) ? false : true;
}
 
class Roots_Nav_Walker extends Walker_Nav_Menu {
  function check_current($classes) {
    return preg_match('/(current[-_])|active|dropdown/', $classes);
  }

  function start_lvl(&$output, $depth = 0, $args = array()) {
    $output .= "\n<ul class=\"dropdown-menu\">\n";
  }

  function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
    $item_html = '';
    parent::start_el($item_html, $item, $depth, $args);

    if ($item->is_dropdown && ($depth === 0)) {
      $item_html = str_replace('<a', '<a class="dropdown-toggle" data-toggle="dropdown" data-target="#"', $item_html);
      $item_html = str_replace('</a>', ' <b class="caret"></b></a>', $item_html);
    }
    elseif (stristr($item_html, 'li class="divider')) {
      $item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
    }
    elseif (stristr($item_html, 'li class="dropdown-header')) {
      $item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
    }

    $item_html = apply_filters('roots_wp_nav_menu_item', $item_html);
    $output .= $item_html;
  }

  function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
    $element->is_dropdown = ((!empty($children_elements[$element->ID]) && (($depth + 1) < $max_depth || ($max_depth === 0))));

    if ($element->is_dropdown) {
      $element->classes[] = 'dropdown';
    }

    parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
  }
}

/**
 * Remove the id="" on nav menu items
 * Return 'menu-slug' for nav menu classes
 */
function roots_nav_menu_css_class($classes, $item) {
  $slug = sanitize_title($item->title);
  $classes = preg_replace('/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes);
  $classes = preg_replace('/^((menu|page)[-_\w+]+)+/', '', $classes);

  $classes[] = 'menu-' . $slug;

  $classes = array_unique($classes);

  return array_filter($classes, 'is_element_empty');
}
add_filter('nav_menu_css_class', 'roots_nav_menu_css_class', 10, 2);
add_filter('nav_menu_item_id', '__return_null');

/**
 * Clean up wp_nav_menu_args
 *
 * Remove the container
 * Use Roots_Nav_Walker() by default
 */
function roots_nav_menu_args($args = '') {
  $roots_nav_menu_args['container'] = false;

  if (!$args['items_wrap']) {
    $roots_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
  }

  if (current_theme_supports('bootstrap-top-navbar') && !$args['depth']) {
    $roots_nav_menu_args['depth'] = 2;
  }

  if (!$args['walker']) {
    $roots_nav_menu_args['walker'] = new Roots_Nav_Walker();
  }

  return array_merge($args, $roots_nav_menu_args);
}
add_filter('wp_nav_menu_args', 'roots_nav_menu_args');


//Relative date modified from wp-includes/formatting.php
function ipin_human_time_diff( $from, $to = '' ) {
	if ( empty($to) )
		$to = time();
	$diff = (int) abs($to - $from);
	if ($diff <= 3600) {
		$mins = round($diff / 60);
		if ($mins <= 1) {
			$mins = 1;
		}

		if ($mins == 1) {
			$since = sprintf(__('%s min ago', 'ipin'), $mins);
		} else {
			$since = sprintf(__('%s mins ago', 'ipin'), $mins);
		}
	} else if (($diff <= 86400) && ($diff > 3600)) {
		$hours = round($diff / 3600);
		if ($hours <= 1) {
			$hours = 1;
		}
		
		if ($hours == 1) {
			$since = sprintf(__('%s hour ago', 'ipin'), $hours);
		} else {
			$since = sprintf(__('%s hours ago', 'ipin'), $hours);
		}
	} else if ($diff >= 86400 && $diff <= 31536000) {
		$days = round($diff / 86400);
		if ($days <= 1) {
			$days = 1;
		}

		if ($days == 1) {
			$since = sprintf(__('%s day ago', 'ipin'), $days);
		} else {
			$since = sprintf(__('%s days ago', 'ipin'), $days);
		}
	} else {
		$since = get_the_date();
	}
	return $since;
}


//Comments
function ipin_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
	?>
	<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">

		<?php if ('1' == $show_avatars = get_option('show_avatars')) { ?>
		<div class="comment-avatar"><?php echo get_avatar(get_comment_author_email(), '32'); ?></div>
		<?php } ?>

		<div class="pull-right"><?php comment_reply_link(array('reply_text' => __('Reply', 'ipin'), 'depth' => $depth, 'max_depth'=> $args['max_depth'])) ?></div>
		
		<div class="comment-content<?php if ($show_avatars == '1') { echo ' comment-content-with-avatar'; } ?>">
			
			<strong><span <?php comment_class(); ?>><?php comment_author_link() ?></span></strong> / <?php comment_date('j M Y g:ia'); ?> <a href="#comment-<?php comment_ID() ?>" title="<?php esc_attr_e('Comment Permalink', 'ipin'); ?>">#</a> <?php edit_comment_link('e','',''); ?>
			<?php if ($comment->comment_approved == '0') : ?>
			<br /><em><?php _e('Your comment is awaiting moderation.', 'ipin'); ?></em>
			<?php endif; ?>
	
			<?php comment_text() ?>
        </div>
	<?php
}

function ipin_commentform_format($arg) {
	$commenter = wp_get_current_commenter();
	$req = get_option( 'require_name_email' );
	$aria_req = ( $req ? " aria-required='true'" : '' );
	$arg['author'] = '<div class="commentform-input pull-left"><label>' . __('Name (Required)', 'ipin') . '</label> <input class="form-control commentform-field" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '"' . $aria_req . ' /></div>';
	$arg['email'] = '<div class="commentform-input pull-left"><label>' . __('Email (Required)', 'ipin') . '</label> <input class="form-control commentform-field" id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '"' . $aria_req . ' /></div>';
	$arg['url'] = '<div class="commentform-input pull-left"><label>' . __('Website', 'ipin') . '</label> <input class="form-control commentform-field" id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '"' . $aria_req . ' /></div>';
    return $arg;
}
add_filter('comment_form_default_fields', 'ipin_commentform_format');


//Feed content for posts
function ipin_feed_content($content) {
	global $post;
	
	$imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
	if ($imgsrc[0] != '') {
		$content_before = '<p><a href="' . get_permalink($post->ID) . '"><img src="' . $imgsrc[0] . '" alt="" /></a></p>';
	}
	
	return ($content_before . $content);
}
add_filter('the_excerpt_rss', 'ipin_feed_content');
add_filter('the_content_feed', 'ipin_feed_content');

?>

Please I really need help, I'm starting my first little web project.

@mguenscher
Copy link

So which theme I can use to see how it work?

@tw2113
Copy link
Member Author

tw2113 commented Mar 14, 2017

The question isn't around theme, it's around making sure the posts you're trying to display have a featured image associated at the time of display. Both your single.php and index.php files have spots that check and try to display the featured image, so why it may not be, depends on one being set.

@tw2113
Copy link
Member Author

tw2113 commented Mar 14, 2017

@mguenscher also see my reply at #5 (comment) as it highlights findings I made last November regarding featured images, and how the aggregated area tries to handle the topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants