-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews-box.php
134 lines (130 loc) · 5.11 KB
/
news-box.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/* This part of code displays the news for the theme.
* It accepts some external variables as parameters:
* Please include this file with
* require(locate_template('news-box.php'));
* You can set the following variables:
* $news_name: Name of the category containing the news posts
* or
* $news_id: ID of the category containing the news posts
**/
define("NumberOfPosts", 6);
define("StdNewsCategoryName", 'News');
define("DefaultImageUrlNamePart",'/images/NewsDefault'); //Should be 64x64px; if a image tries to add the first category to the image if
define("DefaultImageUrlExtension", '.jpg');
define("TemplateDirectory", get_template_directory_uri());
/*-------------------------*/
$args = array('orderby'=>array('date'=>'DESC'),'numberposts'=>NumberOfPosts,'post_status'=>"publish",'post_type'=>"post");
if (isset($news_name))
{
$args['category_name'] = $news_name;
} else if (isset($news_id)) {
$args['cat'] = $news_id;
} else {
$args['category_name'] = StdNewsCategoryName; //Standard News Category Name -
}
$postslist = get_posts($args);
function getImageUrl($post)
{
$attch = FALSE;
if (is_object($post)) {
$attch = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(64,64));
if ($attch == false) {
$attch = getAttachementImageUrl($post);
}
if ($attch == false) {
return getDefaultImageUrl($post);
}
else {
return $attch[0];
}
} else {
return $defaultImage;
}
}
function getAttachementImageUrl($post)
{
$attch = false;
$attachments = get_posts(array('post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID));
if (count($attachments) > 0) {
$attch = wp_get_attachment_image_src($attachments[0]->ID, array(64,64));
}
return $attch;
}
function getDefaultImageUrl($post)
{
$defaultImage = TemplateDirectory . DefaultImageUrlNamePart . DefaultImageUrlExtension;
$categoryImagePath = getDefaultCategoryImagePath($post);
if (file_exists($categoryImagePath)) {
return getDefaultCategoryImageUrl($post);
} else {
return $defaultImage;
}
}
function getDefaultCategoryImageUrl($post)
{
return TemplateDirectory . getDefaultCategoryImagePath($post);
}
function getDefaultCategoryImagePath($post)
{
$categoryName = get_the_category_name($post->ID);
$categoryName = str_replace(' ', '_', $categoryName);
return DefaultImageUrlNamePart . '_' . $categoryName . DefaultImageUrlExtension;
}
function get_the_category_name($postId) {
$cat = get_the_category($postId);
return $cat[0]->cat_name;
}
function custom_excerpt_length($length) {
return 125; //Change this number to any integer you like.
}
function new_excerpt_more($more) {
global $post;
return ' …'; //' <a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
}
add_filter('excerpt_length', 'custom_excerpt_length' );
add_filter('excerpt_more', 'new_excerpt_more');
?>
<div class="newsbox">
<h1 class="news_headline">News</h1>
<div class="partseperator"></div>
<div class="news_list">
<ul class="media-list">
<?php foreach ($postslist as $post) : setup_postdata($post); ?>
<li class="media">
<a class="pull-left" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('preview64x64'); ?>
<?php else : ?>
<img class="media-object size-64x64" width="64" height="64"
src="<?php echo getImageUrl($post); ?>"
alt="<?php the_title(); ?>">
<!-- Categorie Image URL: <?php echo getDefaultCategoryImageUrl($post) ?>-->
<?php endif; ?>
</a>
<h4 class="media-heading"><a href="<?php the_permalink(); ?>"
title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a>
<small>vom <?php the_time('j. F Y, G:i'); ?> Uhr</small></h4>
<small class="media-subline">von <?php the_author(); ?>,
eingeordnet in <span><?php the_category(', '); ?></span></small>
<div class="media-body">
<div class="news-content">
<?php the_advanced_excerpt('length=55&length_type=words&no_custom=1&ellipsis=%26hellip;&allowed_tags=br,p,i,em'); ?>
<p class="read-all">
<a class="read-all-link"
href="<?php the_permalink(); ?>"
title="<?php the_title(); ?>"
target="_blank">Alles lesen »</a>
</p>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
<!--
<p class="allnews_link"><a href="http://blog.cvjm-nuernberg.de/" target="_blank">Alle News</a></p>
/-->
</div>