Change order by date on category wordpress - php

I need help with a product category page in Wordpress. Original code was made by someone else, and I'm fairly new to php. I may need help with looking for a way to make the product sort by date published. right now, here is the code that I have.
category-books.php
<?php
/**
* Template Name: Store Template
* #package WordPress
*/
get_header(); ?>
<div id="page-title">
<!-- 960 Container Start -->
<div class="container">
<div class="sixteen columns">
<h1>
<?php single_cat_title( '', true ); ?>
</h1>
</div>
</div>
<!-- 960 Container End -->
</div>
<?php
get_template_part( 'content', 'product4' ); ?>
<div class="blogsidebar" style="float:left !important">
<?php dynamic_sidebar('sidebar-1'); ?>
</div>
<?php get_footer(); ?>
content-product4.php
<?php function bac_wp_strip_header_tags_only( $excerpt ) {
$regex = '#(<h([1-6])[^>]*>)#';
$excerpt = preg_replace($regex,'', $excerpt);
return $excerpt;
}
add_filter( 'the_content', 'bac_wp_strip_header_tags_only', 0); ?>
<div class="container">
<?php $sidebar_side = get_post_meta($post->ID, 'incr_sidebar_layout', true);
if($sidebar_side == "left-sidebar") {
get_sidebar();
} ?>
<!-- Blog Posts ================================================== -->
<div class="twelve columns" style="float:right !important;">
<div class="product-container">
<?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- Post -->
<div <?php post_class('post'); ?> id="product-post-2Col" > <a class="post_title" href="<?php the_permalink() ?>">
<div style="margin-bottom:10px;width: 130px;height: 180px !important; border: 2px solid #000 !important;padding: 3px;float: left;margin: 0 15px 15px 0;overlay:hidden;">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail( 'medium', array( 'class' => 'store-featured-image' ) );
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/product-image.png" alt="<?php the_title(); ?>" />
<?php } ?>
</div>
<div style="min-height:40px !important;width:50% !important;float:left;">
<h4>
<?php the_title(); ?>
</h4>
</a> </div>
<?php?>
<div class="product-description-2col">
<?php the_excerpt()?>
<a style="margin-bottom: 8px;" class="post_title" href="<?php the_permalink() ?>">Learn More</a><br/>
<?php ?>
<a href="<?php the_field('buy_now_1')?>">
<div id="buybtn">Buy Now</div>
</a>
<?php ?>
</div>
<?php ?>
<p> </p>
<p> </p>
</div>
<!-- Post -->
<?php endwhile; // End the loop. Whew. ?>
</div>
<div style="text-align:center;">
<?php posts_nav_link( ' · ', 'previous page', 'next page' ); ?>
</div>
</div>
<!-- eof eleven column -->
is there a way to add something to functions.php? I've added this line but still not working:
<?php $posts = query_posts($query_string . 'orderby=date&order=DESC&cat=238'); ?>
<?php while (have_posts()) : the_post(); ?>
Thanks for the help.

Instead of using functions.php for this, create a child theme and edit a copy of the file you want to change there.
https://codex.wordpress.org/Child_Themes

Related

How to prevent image captions from appearing in the main page (posts) content?

I am displaying an image and a text excerpt of the posts on my landing page. However I would like to prevent image captions from appearing on those excerpts.
Is there an quick way of doing this?
<?php while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<?php the_post_image('thumbnail'); ?>
</p>
<p>
<?php the_content_rss('', TRUE, '', 40); ?>Read More
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>
add this code to your functions.php
function excerpt_bz( $content, $limit=25, $endPoints = '[...]', $tags_accepts = '' ) {
$excerpt = explode(' ', strip_tags($content, $tags_accepts), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' '.$endPoints;
} else {
$excerpt = implode(" ",$excerpt);
}
return $excerpt;
}
note that this pulls the content and cuts it and you pass the allowed data
<?php while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID() ?>" class="<?php /*sandbox_post_class()*/ ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<!--here you have greater control -->
<figure>
<?php get_the_post_thumbnail('thumbnail'); ?>
</figure>
</a>
</p>
<p>
<!-- use ( note that this function you need to fill the field in the panel in wp )-->
<?php the_excerpt(); ?>
<!-- or (note that this pulls the content and cuts it and you pass the allowed data) -->
<?php echo excerpt_bz( get_the_content(), 500, '...', '<a><p><br><strong><em>' ) ?>
Read More
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>
Got it by replacing the "the_content_rss" for "the_excerpt"
<div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
<div class="entry-meta clearfix">
<h2 class="entry-title"><?php the_title() ?></h2>
</div>
<div class="entry-content">
<p class="thePic clearfix">
<?php the_post_image('thumbnail'); ?>
</p>
<p>
<?php the_excerpt('', TRUE, '', 40); ?><div class="read-more">Read More</div>
</p>
</div><!-- .entry-content -->
</div><!-- .post -->
<?php endwhile ?>

Why it gives random post ID

I am building a WordPress theme. I am having some trouble on commenting section. When showing comments it gets randomly post ID.
I have put the same code in 2 different places in the first place it TOP but by at BOTTOM its not working. Can anyone help me by telling why is this not working at bottom?!
Here is my single.php file
<?php get_template_part('/template-parts/standard-post-header'); ?>
<main role="main">
<!-- section -->
<section>
<div class="container background-color">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (has_post_video( isset($post_id) ) != null) {
// Featured VIDEO -->
get_template_part('/template-parts/featured-video-post');
// END Featured VIDEO -->
} else { ?>
<!-- Featured Image -->
<?php $header_type = get_post_meta(get_the_id(), 'meta-box-dropdown', true); ?>
<?php if ($header_type == 'Slider') {
// SLIDER Header
get_template_part('/template-parts/featured-slider-post');
?>
<?php } else {
// SLIDER Header
get_template_part('/template-parts/featured-normal-post');
} ?>
<!-- END Featured Image -->
<?php } ?>
<div class="container container-post-color">
<div class="content">
<?php the_content(); ?>
<?php edit_post_link(); ?>
</div>
</div>
<?php
global $post;
echo $post->ID;
?>
<ol class="commentlist">
<?php
//THIS WORKS!!!
$comments = get_comments(array(
'post_id' => $post->ID,
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 10,
'reverse_top_level' => false
), $comments);
?>
</ol>
<!-- Post Navigation -->
<div class="container container-post-color top-space" style="padding-left: 0px; padding-right: 0px;">
<div id="left-side"><?php previous_post_link(); ?></div>
<div id="right-side"><?php next_post_link(); ?></div>
<?php echo wp_link_pages(); ?>
</div>
<!-- Tags -->
<div class="tags-area">
<?php echo the_tags(); ?>
</div>
<!-- Related Articles -->
<?php get_template_part('/template-parts/related-articles'); ?>
<!-- Coments Part -->
<?php //get_template_part('/template-parts/comments'); ?>
<?php
global $post;
echo $post->ID;
?>
<ol class="commentlist">
<?php
//THIS DOES NOT WORKS!!! WHY?!
$comments = get_comments(array(
'post_id' => $post->ID,
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 10,
'reverse_top_level' => false
), $comments);
?>
</ol>
</article>
<!-- /article -->
</div>
<!-- END of Container-Fluid -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<div class="container background-color">
<h1 class="black mastheading-post"><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</div>
</article>
<!-- /article -->
<?php endif; ?>
</section>
<!-- /section -->
</main>
<!-- INSTAGRAM -->
<?php get_template_part('/template-parts/instagram'); ?>
<?php get_footer(); ?>
related-articles.php
<div class="container container-post-color" style="padding-left: 0px; padding-right: 0px;">
<div class="random">
<ul>
<?php $posts = get_posts('orderby=rand&numberposts=4'); foreach($posts as $post) { ?>
<div class="col-md-3 padding-zero">
<li>
<div class="random-thumb">
<?php the_post_thumbnail('full'); ?>
</div>
<div class="random-title">
<h1 class="black mastheading"><?php the_title(); ?></h1>
</div>
<div class="black iltalica"><?php echo excerpt(25); ?></div>
<div class="category">
<div class="random-category">
<h5><?php echo the_category();?></h5>
</div>
</div>
</li>
</div>
<?php } ?>
</ul>
</div>
</div>
So first off, since you are in the loop, everywhere you've used global $post; ... $post->ID you should be able to use get_the_ID() instead.
Second, I strongly suspect the problem is your template part /template-parts/related-articles probably messes-up the main loop. I suggest you look at that file and see if it's itself looping on a selection of posts - chances are it is not doing it cleanly, in a way that can be re-used inside the main loop.
You can add that file's code to your question if you need help figuring it out.
UPDATE
Ok, so indeed, you need to reset the loop data after the related-articles loop:
...
<?php
}
wp_reset_postdata(); // <----- add this after your loop
?>
</ul>
...
Hope this helps!

Centering an objekt in php template. How?

I have a little problem with aligning a logo with some text in wordpress.
The more transparent logo is where I want my logo to be. It is in my header.php in my wordpress theme "Creator World".
I Really dont know what to do I have tried to research and I couldn't find anything. Hope you can help me 😀
The more transparent logo and the arrow is sat in, in an design app
Here is my php code for my header.php in wordpress
<?php
/**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <div class="container">
*
* #package Creator World
*/
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="pagewrap">
<div class="headertop">
<div class="container">
<?php if ( ! dynamic_sidebar( 'header-info' ) ) : ?>
<?php endif; // end header widget area ?>
</div><!-- .container -->
</div><!-- .headertop -->
<div class="header">
<div class="container">
<div class="logo">
<?php creator_world_the_custom_logo(); ?>
<h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php bloginfo('name'); ?>
</a></h1>
<p>
<?php bloginfo('description'); ?>
</p>
</div><!-- logo -->
<div class="toggle"> <a class="toggleMenu" href="#">
<?php _e('Menu','creator-world'); ?>
</a> </div> <!-- toggle -->
<div class="sitenav">
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
</div>
<!-- site-nav -->
<div class="clear"></div>
</div><!-- container -->
</div><!--.header -->
<?php if ( is_front_page() && !is_home() ) { ?>
<?php $hideslide = get_theme_mod('disabled_slides', '1'); ?>
<?php if($hideslide == ''){ ?>
<?php for($sld=7; $sld<10; $sld++) { ?>
<?php if( get_theme_mod('page-setting'.$sld)) { ?>
<?php $slidequery = new WP_query('page_id='.get_theme_mod('page-setting'.$sld,true)); ?>
<?php while( $slidequery->have_posts() ) : $slidequery->the_post();
$image = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
$img_arr[] = $image;
$id_arr[] = $post->ID;
endwhile;
}
}
?>
<?php if(!empty($id_arr)){ ?>
<div id="slider" class="nivoSlider">
<?php
$i=1;
foreach($img_arr as $url){ ?>
<?php if(!empty($url)){ ?>
<img src="<?php echo $url; ?>" title="#slidecaption<?php echo $i; ?>" />
<?php }else{ ?>
<img src="<?php echo esc_url( get_template_directory_uri() ) ; ?>/images/slides/slider-default.jpg" title="#slidecaption<?php echo $i; ?>" />
<?php } ?>
<?php $i++; } ?>
</div>
<?php
$i=1;
foreach($id_arr as $id){
$title = get_the_title( $id );
$post = get_post($id);
$content = esc_html( wp_trim_words( $post->post_content, 20, '' ) );
?>
<div id="slidecaption<?php echo $i; ?>" class="nivo-html-caption">
<div class="slide_info">
<h2><?php echo $title; ?></h2>
<p><?php echo $content; ?></p>
</div>
</div>
<?php $i++; } ?>
<?php wp_reset_postdata(); ?>
<div class="clear"></div>
<?php } ?>
<?php } } ?>
<?php if ( is_front_page() && ! is_home() ) { ?>
<?php $hidewelcome = get_theme_mod('disabled_welcome', '1'); ?>
<?php if($hidewelcome == ''){ ?>
<section id="welcomesection">
<div class="container">
<div class="welcomebx">
<?php if( get_theme_mod('page-setting1')) { ?>
<?php $queryvar = new WP_query('page_id='.get_theme_mod('page-setting1' ,true)); ?>
<?php while( $queryvar->have_posts() ) : $queryvar->the_post();?>
<h2 class="headingtitle">
<?php the_title(); ?>
</h2>
<?php the_content(); ?>
<div class="clear"></div>
<?php endwhile;
wp_reset_postdata(); ?>
<?php } ?>
</div> <!-- welcomewrap-->
<div class="clear"></div>
</div> <!-- container -->
</section>
<?php } ?>
<?php $hidepgbxes = get_theme_mod('disabled_pageboxes', '1'); ?>
<?php if($hidepgbxes == ''){ ?>
<section id="wrapsecond">
<div class="container">
<div class="services-wrap">
<?php for($p=1; $p<5; $p++) { ?>
<?php if( get_theme_mod('page-column'.$p,false)) { ?>
<?php $querymy = new WP_query('page_id='.get_theme_mod('page-column'.$p,true)); ?>
<?php while( $querymy->have_posts() ) : $querymy->the_post(); ?>
<div class="fourbox <?php if($p % 4 == 0) { echo "last_column"; } ?>">
<?php if(has_post_thumbnail() ) { ?>
<div class="thumbbx"><?php the_post_thumbnail();?> </div>
<?php } ?>
<div class="pagecontent">
<h3><?php the_title(); ?></h3>
<p><?php echo wp_trim_words( get_the_content(), 20, '...' ); ?></p>
<a class="pagemore" href="<?php the_permalink(); ?>">
<?php _e('Read More','creator-world'); ?>
</a>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
<?php } } ?>
<div class="clear"></div>
</div> <!-- services-wrap-->
</div> <!-- container -->
</section>
<?php } ?>
<?php } ?>
You can't center a logo through php. The right way will be css. Search by css and you will find many ways to achieve this. Or post the link of your site so that we can help you.
Try changing the code to the following, adding a new div with class brand-name and leaving only the logo in the one with logo class.
<div class="header">
<div class="container">
<div class="brand-name">
<h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php bloginfo('name'); ?>
</a></h1>
<p>
<?php bloginfo('description'); ?>
</p>
</div>
<div class="logo">
<?php creator_world_the_custom_logo(); ?>
</div><!-- logo -->
<div class="toggle"> <a class="toggleMenu" href="#">
<?php _e('Menu','creator-world'); ?>
</a> </div> <!-- toggle -->
<div class="sitenav">
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
</div>
<!-- site-nav -->
<div class="clear"></div>
</div><!-- container -->
</div><!--.header -->
Then, add the following lines in CSS:
.brand-name, .logo {
display: inline-block;
}
try wrapping the logo and title to the individual div elements
<div class="header">
<div class="container">
<div class="brand-title pull-left">
<h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php bloginfo('name'); ?>
</a></h1>
<p>
<?php bloginfo('description'); ?>
</p>
</div><!-- Brand Title -->
<div class="brand-logo pull-left">
<?php creator_world_the_custom_logo(); ?>
</div><!-- Brand logo -->
<div class="toggle"> <a class="toggleMenu" href="#">
<?php _e('Menu','creator-world'); ?>
</a> </div> <!-- toggle -->
<div class="sitenav">
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
</div>
<!-- site-nav -->
<div class="clear"></div>
</div><!-- container -->
</div><!--.header -->
and then add the following code to your CSS file (usually this is style.css)
.pull-left {
float: left;
}

WordPress Blog, only use archive for current page?

I am building a WP site, which will have a News and Blog.
They will be in separate pages, One for news and one for Blog, which will be separated by categories.
So for example, I have this code on 'News', which stops the loop getting posts:
<?php
$uncat = get_cat_ID('uncategorised');
$uncat2 = get_cat_ID('blog');
$args = array(
'posts_per_page' => 3,
'category__not_in' => array($uncat, $uncat2)
);
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<div class="col-md-12 col-sm-12 col-xs-12" style="padding-left:0; padding-right:0;">
<a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
<div class="postsize">
<div class="leftfloat" style="float: left; padding-right:20px;">
<?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>
</div>
<div class="contentfaq">
<h4><?php the_title(); ?></h3>
<span class="entry-date-blue"><strong><?php echo get_the_date('d/m/y'); ?></strong></span>
<?php $trimexcerpt = get_the_excerpt();
$shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> Read More ...' );
echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>';
?>
</div>
</div>
</div>
</a>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
This works fine, but I also have 'Archives' on the right hand side, which filters by date posted. The issue is, this will get posts from News AND blog, which defeats the idea of splitting them up.
Is there a way to split these up, so if the user clicks 'March 2015' on the archive, it will only get the posts from this month from NEWS?
Here is my current code for Archive.php
<?php if (have_posts()) : ?>
<!-- First, the loop checks whether any posts were discovered with the have_posts() function. -->
<!-- If there were any posts, a PHP while loop is started. A while loop will continue to execute as long as the condition in the parenthesis is logically true. So, as long as the function have_posts() returns a true value, the while loop will keep looping (repeating). -->
<?php while (have_posts()) : the_post(); ?>
<div class="col-md-12 col-sm-12 col-xs-12">
<a href="<?php echo get_permalink(); ?>">
<div class="postsize">
<div style="float: left; padding-right:20px;">
<?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>
</div>
<h5 class="captext"><?php the_title(); ?></h5>
<span class="entry-date-orange"><?php echo get_the_date(); ?></span>
<?php
foreach((get_the_category()) as $category) {
echo ' | ' . $category->cat_name;
}
?>
<p style="margin-top:10px";><?php the_excerpt(); ?></p>
</div>
</a>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Try this , it will echo list
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
full example code
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_search_form(); ?>
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Working with external loop in two different situations in same site (WP)

In my theme I have a blog page and a homepage (without blog loop). Now I would like to add some blog posts on my homepage (like most recent).
I am using the blog page as a template for the homepage ( I copied and renamed the original), wich works good. But I can't make any changes to it without changing the original blog page (the loop is called in an external php).
I Have no idea were to start.
This is the piece on the homepage calling the blog loop:
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<?php if($gallery_select && $gallery_position == 1) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php codeus_blog_list(); ?>
</div>
<?php if($quickfinder_position == 2) : ?>
<?php codeus_quickfinder($quickfinder_select); ?>
<?php endif; ?>
<?php if($portfolio_position == 2) : ?>
<?php codeus_portfolio(implode(',',$portfolio_select), $portfolio_size, $portfolio_count, $portfolio_filter, $portfolio_title); ?>
<?php endif; ?>
<?php if($gallery_select && $gallery_position == 3) : ?>
<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
<?php endif; ?>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->
And this is the piece in the external php called blog.php
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"> </div>
<img src=" <?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
<?php codeus_pagination($page_num, $pages_count); ?>
</div>
<?php endif; ?>
Remember, I don't want to make changes in the original blog.php, because the normal blog page needs to work as it is now. I would like to make the blog work on the homepage also, but just with a maximum of 3 posts showing, perhaps of a certain category.
Help would be so welcome!!
I think I found a solution, I edited the homepage template like this:
<!-- wrap start --><div class="content-wrap">
<?php if(have_posts()) : the_post(); ?>
<div id="main">
<div class="central-wrapper clearfix">
<div id="center" class="fullwidth">
<div id="content">
<div class="inner">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<div class="bloghome">
<?php
$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;
$items_per_page = 2;
$blog_loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => $items_per_page,
'paged' => $page_num
));
$pages_count = ceil($blog_loop->found_posts/$items_per_page);
global $post;
$portfolio_posttemp = $post;
?>
<?php if($blog_loop->have_posts()) : ?>
<div class="blog_list">
<ul class="styled">
<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
<li class="clearfix">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
<div class="comment-info">
<?php echo get_the_date('d'); ?>
<div class="date-month"><?php echo get_the_date('M'); ?></div>
</div>
<div class="post-info">
<h3><?php the_title(); ?></h3>
<?php if($image_url[0]) : ?>
<div class="post-image">
<div class="image wrap-box shadow middle">
<div class="shadow-left"></div><div class="shadow-right"></div>
<img src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" />
</div>
</div>
<?php endif; ?>
<div class="text clearfix"><?php the_excerpt(); ?></div>
<?php codeus_author_info(get_the_ID()); ?>
</div>
</div>
</li>
<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
</div><!-- #content -->
</div><!-- #center -->
</div><!-- .central-wrapper -->
</div><!-- #main -->
<?php endif; ?>
</div><!-- wrap end -->

Categories