I've been trying to turn my simple html/css site into a wordpress site. my big issue which no one seem to be able to solve appears in my footer. The footer is pretty much ignoring everything and just staying in the top of the site ( like it was a part of my header). All my files is split into 3 files. A header.php a footer.php and the page.php (one for each site).
Header!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<?php if (is_search()) { ?>
<meta name="robots" content="noindex, nofollow" />
<?php } ?>
<title>
<?php
if (function_exists('is_tag') && is_tag()) {
single_tag_title("Tag Archive for ""); echo '" - '; }
elseif (is_archive()) {
wp_title(''); echo ' Archive - '; }
elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - '; }
elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - '; }
elseif (is_404()) {
echo 'Not Found - '; }
if (is_home()) {
bloginfo('name'); echo ' - '; bloginfo('description'); }
else {
bloginfo('name'); }
if ($paged>1) {
echo ' - page '. $paged; }
?>
</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="Menu" ></div>
<div id="Mainbody">
<div id="Portfolio"><?php bloginfo('name'); ?> </div>
<div id="Slogan"><?php bloginfo('description'); ?></div>
<div id="nav-menu">
<?php $defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
); ?>
<?php wp_nav_menu( $defaults ); ?>
</div>
<div class="Box">
<div id="Mainindhold">
page!
<?php get_header(); ?>
<div id="Arbejde">
<h2>Uddrag af mine webdesigns</h2>
<br />
<br />
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $key='link'; $custom = get_post_meta($post->ID, $key, true); ?>
<?php $key2='brugt'; $custom2 = get_post_meta($post->ID, $key2, true); ?>
<?php $key3='linkexternal'; $custom3 = get_post_meta($post->ID, $key3, true); ?>
<?php $billede = get_the_post_thumbnail($post->ID, 'full'); ?>
<div class="Raekke">
<div class="Arbejds_Billede">
<a href="<?php echo $custom; ?>" rel="lightbox">
<?php print $billede; ?></a>
</div>
<div class="Arbejdsbeskrivelse">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<div id="program">
<img src="<?php echo $custom2; ?>" />
</div>
<div class="Knap"><p>Besøg siden</p>
</div>
</div>
</div>
<div class="clear"></div>
<?php endwhile;
else:
?>
<?php _e('No posts were fond. Sorry!'); ?>
<?php endif; ?>
</div>
<?php get_footer();?>
footer !
</div>
</div>
</div>
<div id="footer">
©<?php echo date("Y"); echo " "; bloginfo('name'); ?> 4000 Roskilde
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31920214-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php wp_footer(); ?>
</body>
</html>
To be able to see the issue you can go into Tinajohnson.dk and ofcourse look in the top.
You are calling the footer functions twice in your page: first here:
<?php get_footer();?>
and and here again,
<div id="footer">
©<?php echo date("Y"); echo " "; bloginfo('name'); ?> 4000 Roskilde
</div>
get rid of the second piece and it should work.
This is a CSS problem; add the following rules to your #footer's CSS:
position: absolute;
bottom: 0;
width: 100%;
If you want your stick to bottom of browser always. Use Position Fixed not absolute
css will be for your ID footer Div
#footer { position:fixed; bottom:0; width:100%}
Related
I'm trying to change the header logo on my site, depending on the page the person is on. I don't know PHP, but I've found where the Logo is defined in header.php, and am trying to rewrite it to be dynamic. When I use my code, the site breaks, so obviously I'm doing something wrong.
Here is the code of my header.php file.
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head><meta charset="<?php bloginfo( 'charset' ); ?>">
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.css" integrity="sha256-0LjJurLJoa1jcHaRwMDnX2EQ8VpgpUMFT/4i+TEtLyc=" crossorigin="anonymous" />
<?php
wp_head();
?>
<style>
.chosen-container .chosen-results {
height: 100%;
overflow-y: hidden;
max-height: inherit;
}
.chosen-container-active .chosen-single, .chosen-container-single .chosen-single {
display: none;
}
.chosen-container-single .chosen-drop {
display: contents;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="<?php $themnific_redux = get_option( 'themnific_redux' );
if (empty($themnific_redux['tmnf-uppercase'])) {} else {if($themnific_redux['tmnf-uppercase'] == '1') echo 'upper '; }
if (empty($themnific_redux['tmnf-bottombar-dis'])) {} else {if($themnific_redux['tmnf-bottombar-dis'] == '1') echo 'bottombar_dis '; }
if ( is_active_sidebar( 'tmnf-sidebar' ) ) {echo 'tmnf-sidebar-active ';} else { echo 'postbarNone ';};
if (empty($themnific_redux['tmnf-header-layout'])) {} else {echo esc_attr($themnific_redux['tmnf-header-layout']);}
?>">
<div id="header" class="tranz" itemscope itemtype="http://schema.org/WPHeader">
<div class="container_head">
<a class="screen-reader-text ribbon skip-link" href="#content_start"><?php esc_html_e('Skip to content','citygov');?></a>
<div class="clearfix"></div>
<div id="titles" class="tranz2">
<?php if(empty($themnific_redux['tmnf-main-logo']['url'])) { ?>
<h1 class="logo"><?php bloginfo('name');?></h1>
<?php }
else { ?>
<a class="logo" href="<?php echo esc_url(home_url('/')); ?>">
<img class="tranz" src="<?php echo esc_url($themnific_redux['tmnf-main-logo']['url']);?>" alt="<?php bloginfo('name'); ?>"/>
</a>
<?php } ?>
</div><!-- end #titles -->
<div class="header-right for-menu">
<input type="checkbox" id="showmenu" aria-label="<?php esc_html_e('Open Menu','citygov');?>">
<label for="showmenu" class="show-menu ribbon" tabindex="0"><i class="fas fa-bars"></i> <span><?php esc_html_e('Menu','citygov');?></span></label>
<nav id="navigation" class="rad tranz" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation" aria-label="<?php esc_html_e( 'Main Menu', 'citygov' ); ?>">
<?php get_template_part('/includes/navigation'); ?>
</nav>
</div><!-- end .header-right -->
<div class="clearfix"></div>
<div id="bottombar" class="bottomnav tranz" role="navigation" aria-label="<?php esc_html_e( 'Quick Links', 'citygov' ); ?>">
<?php if(empty($themnific_redux['tmnf-menu-label'])) {} else { ?>
<p class="menu_label"><?php echo esc_attr($themnific_redux['tmnf-menu-label']); ?></p>
<?php }?>
<div class="header-right">
<?php get_template_part('/includes/add-navigation'); ?>
<?php get_template_part('/includes/uni-social' );?>
</div>
</div><!-- end #bottombar -->
<div class="clearfix"></div>
</div><!-- end .container -->
</div><!-- end #header -->
<?php ?>
<div class="wrapper p-border">
You can do this by simply put below code in your theme's functions.php file.
after putting this code, you can now see the new settings added into back-end admin area.
Go to the wordpress admin area then go to Appearance > Customize > Site Identity.
You can now see there are two new settings.
1)Upload Logo (replaces text) => You can add second logo for other pages
2) Page IDs. => You can add comma separated page ids in this text box for displaying second logo in that pages.
function jay_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'jay_logo' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'jay_logo', array(
'label' => __( 'Upload Logo (replaces text)', 'jay' ),
'section' => 'title_tagline',
'settings' => 'jay_logo',
) ) );
$wp_customize->add_setting('page_ids');
$wp_customize->add_control('text_setting', array(
'label' => 'Page IDs',
'section' => 'title_tagline',
'type' => 'text',
'settings' => 'page_ids',
));
}
add_action( 'customize_register', 'jay_customize_register' );
function change_logo_on_single($html) {
$pageIDs = (get_theme_mod('page_ids'))? explode(',',get_theme_mod('page_ids')) : array();
if(in_array(get_the_ID(),$pageIDs)){
$html = preg_replace('/<img(.*?)\/>/', '<img src="'.get_theme_mod('jay_logo').'" class="custom-logo" alt="" itemprop="logo" />', $html);
}
return $html;
}
add_filter('get_custom_logo','change_logo_on_single');
Hi Guys my name is Fotis and i am a junior web developer.
The reason i need your help is because i am trying to create this gallery http://www.elliotcondon.com/creating-an-image-gallery-with-advanced-custom-fields/ and i am using custom fields and the add on repeater.
But i can’t see anything on my browser and in my home page. Why this is happening ? what i am doing wrong?
Please anyone who know to help me
Thank you for reading my request!
Here is my index.php code
<?php
get_header(); ?>
<div id="content">
<div id="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>
<!-- Slider -->
<?php if(get_field('images')): ?>
<div id="slider">
<?php while(the_repeater_field('images')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('image'), 'full'); ?>
<?php $thumb = wp_get_attachment_image_src(get_sub_field('image'), 'thumbnail'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_sub_field('title');?>" rel="<?php echo $thumb[0]; ?>" />
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
</div>
The problem is solved by making a frontpage .php ,in which you include all the index .php code.Then in settings you set front page the home page you've made and posts page the blank blog page. And so simple you can fix the problem.Here is the frontpage.php i made and i solved my problem.
<?php
/**
* Template Name: front-page.php Template
*/
get_header(); ?>
<?php
$args = array( 'posts_per_page' => 10 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post ); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endforeach;
//for each category, show 3 posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => 3,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><?php the_title(); ?></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
wp_reset_postdata(); ?>
<?php global $post;
$pid = $post->ID;
get_field('slide',$pid);
?>
<!-- Slider -->
<div class="flexslider">
<ul class="slides">
<?php
$rows = get_field('slide');
if($rows) {
foreach($rows as $row) {
// retrieve size 'large' for background image
$bgimg = $row['bg_image']['sizes']['large'];
$output = "<li style='background-image: url(". $bgimg .");'>\n";
$output .= " <div class='slide-text'>\n";
$output .= " <h2>". $row['slide_heading'] ."</h2>\n";
$output .= " " . $row['slide_text'];
$output .= " </div>\n";
$output .= "</li>\r\n\n";
$output .= " " . $row['slide_link'];
echo $output;
}
}
?>
</ul>
</div>
</div>
</div>
<?php get_footer(); ?
Here is the functions.php file in which you set the template for each page.
<?php
/***********************************************************************************************/
/* Define Constants */
/***********************************************************************************************/
define('THEMEROOT', get_stylesheet_directory_uri());
define('IMAGES', THEMEROOT.'/images');
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );
// Add support for featured images
add_theme_support( 'post-thumbnails' );
function get_future_posts($post_type, $require_featured, $number_posts=1) {
$today = current_time( 'timestamp' );
$posts = get_posts(array(
'posts_per_page' => $number_posts,
'post_type' => $post_type,
'meta_key' => 'date_time',
'meta_compare' => '>=',
'meta_value' => $today,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'featured_event',
'value' => $require_featured
)
)
));
return $posts;
}
add_action('init', 'my_custom_init');
function my_custom_init() {
// remember add first parameter post type as 'page'
add_post_type_support( 'page', 'page-attributes' );
}
// Load our scripts
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
?>
And of course the header.php
<head>
<!-- Page Meta -->
<meta http-equiv="content-type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />
<title><?php wp_title( '-', true, 'right' ); echo esc_html( get_bloginfo('name'), 1 ); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url') ?>" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url') ?>/css/flexislider.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.flexislider.js"type="text/javascript"></script>
<script>
(function($) {
$(window).load(function() {
$('.flexslider').flexslider({
animation: 'slide',
controlsContainer: '.flex-container'
});
});
})(jQuery)
</script>
<?php wp_head(); ?>
</head>
<nav>
<div class="container">
<ul class="nav-list">
<li>Αρχική</li>
<li>Χρήσιμα</li>
<li>Κοινωνικά</li>
<li>Διάφορα</li>
<li>Αθλητικά</li>
<li>Ειδήσεις</li>
<li>Εκδηλώσεις</li>
</ul>
</div>
</nav>
</header>
And finally this is the code in order to develop a flexi slider with ACF Repeater.
Enjoy!
Has anyone been able to implement Twitter Bootstrap carousel with keyboard controls? I know this is going to be implement in the next release, but for now I was wondering if any of you has been able to make it work.
Here's my current code:
<script type="text/javascript">
jQuery(document).keypress(function(event) {
if (event.keyCode === RIGHT_ARROW) {
$('a.carousel-control.right').trigger('click');
}
if (event.keyCode === LEFT_ARROW) {
$('a.carousel-control.left').trigger('click');
}
});
</script>
But I'm not getting anywhere with this. Any ideas?
Edit: Here's the Wordpress code I am running...
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<?php if ( $post->post_type == 'portfolios' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
'orderby' => 'menu_order',
'order' => 'ASC'
) );
?>
<?php if ( $attachments ) {
$the_rest = array_slice($attachments, 0, 100);
?>
<div id="carousel-<?php the_ID(); ?>" class="featured-carousel carousel slide carousel-fade">
<div class="carousel-inner">
<?php
global $post;
$post_num = 0;
foreach( $the_rest as $attachment) :
$image = wp_get_attachment_image_src( $attachment->ID, 'orion-thumb-900', false );
$post_num++;
?>
<div class="item <?php if($post_num == 1){ echo 'active'; } ?>">
<?php echo "<img src='" . $image[0] . "'>"; ?>
<div class="container">
</div> <!-- /.container -->
</div> <!-- /.item -->
<?php endforeach; ?>
<?php } ?>
<?php } ?>
</div> <!-- /.carousel-inner -->
<a class="left carousel-control" href="#carousel-<?php the_ID(); ?>" data-slide="prev">‹</a>
<a class="right carousel-control" href="#carousel-<?php the_ID(); ?>" data-slide="next">›</a>
</div> <!-- /.carousel -->
<section class="entry-content clearfix">
<?php the_content(); ?>
<?php orion_related_posts(); ?>
</section> <!-- end article section -->
</article> <!-- end article -->
<?php endwhile; ?>
thanks for that,
Even better with carousel events and devices support - 'click' sucks these days!
$(document).bind('keyup', function(e) {
if(e.which == 39){
$('.carousel').carousel('next');
}
else if(e.which == 37){
$('.carousel').carousel('prev');
}
});
Here's the correct code, thanks DavidChase and Flemingslone!
<script type="text/javascript">
jQuery(document).bind('keyup', function(e) {
if (e.keyCode==39) {
jQuery('a.carousel-control.right').trigger('click');
}
else if(e.keyCode==37){
jQuery('a.carousel-control.left').trigger('click');
}
});
</script>
Okay I am ripping my hair out over this and I know it is super simple and is staring me in the face but I just can't see it. In essence what is happening is that my pagination isn't working. I use the plugin wp_pagenavi (which is not the issue already checked) It gives me a list of links of each page in the pagination. That all works fine, in fact all the code does what it is supposed to do. The problem is when I click on the pagination link such as "2" or "3" it attempts to go to the corresponding pagination ie www.yousitehere.com/somepage/page/2 but instead the site just reloads the current page without the /page/2.
I think somewhere the page either doesn't realize it needs to paginate and therefore ignores all instances of /page or something is resetting the pagination before the page loads. (its not the reset_query).
This is a Wordpress site. Unfortunately I am unable to show the site link which makes it harder for you bu hopefully someone has a suggestion.
here is my code
<div id="content" class="clearfix">
<div id="main" class="col960 left first clearfix" role="cont_detail">
<?php if (have_posts()) : while (have_posts()) : the_post();
$id = get_the_ID();
$array = metadata($id);
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="cont_detail" >
<header>
<div id="header_bg_top"></div>
<div id="header_bg">
<?php if($array['custom_facebook'] !="" && $array['custom_twitter'] !="" && $array['custom_linkedin'] != ""&& $array['custom_website'] != "" && $array['custom_blog'] != "" && $array['custom_email'] != ""){?>
<div class="social_link_container">
<div class="width">
<?php if(isset($array['custom_facebook']) && $array['custom_facebook'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-facebook.png">
<?php }
if(isset($array['custom_twitter']) && $array['custom_twitter'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-twitter.png">
<?php }
if(isset($array['custom_linkedin']) && $array['custom_linkedin'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-in.png">
<?php }
if(isset($array['custom_website']) && $array['custom_website'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-web.png">
<?php }
if(isset($array['custom_blog']) && $array['custom_blog'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-blog.png">
<?php }
if(isset($array['custom_email']) && $array['custom_email'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-email.png"><?php }?>
</div>
</div>
<?php } ?>
<h1 class="cont_detail_title" itemprop="headline"><?php the_title(); ?></h1>
<?php if(isset($array['custom_description']) && $array['custom_description'] !="")
{
?>
<span class="title_description"><?php echo $array['custom_description']; ?></span>
<?php
}
?>
</div><!-- header-bg -->
</header> <!-- end article header -->
<section>
<div class="content-left">
<?php if(isset($array['featured_thumb']) && $array['featured_thumb'] !="")
{
?>
<div class="cont_detail_image">
<?php print_thumbnail($array['featured_thumb'], "medium");?>
</div>
<?php
}
?>
</div>
<div class="content-right">
<?php the_content(); ?>
</div>
</section> <!-- end article section -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1>Not Found</h1>
</header>
<section class="post_content">
<p>Sorry, but the requested resource was not found on this site.</p>
</section>
<footer>
</footer>
</article>
<?php endif;
wp_reset_query();
//Sort queries, most viewed, alphabetical, date
echo '<section><div id="content_bg" class="group">';
$row_num = 1;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if( $_GET['sort'] == 'date' ) {
$sortOrder = getSortOrder( $_GET['dsort_order'] );
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'meta_query' => $meta_queries,
'order'=>$sortOrder,
'orderby'=> 'date',
'posts_per_page' => 9,
'paged' => $paged
));
}
elseif( $_GET['sort'] == 'alpha' ) {
$sortOrder = getSortOrder( $_GET['asort_order'] );
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'meta_query' => $meta_queries,
'order'=>$sortOrder,
'orderby'=> 'title',
// adding posts_per_page, set to 9 might be different then global preference
'posts_per_page' => 9,
'paged' => $paged
));
}
elseif( $_GET['sort'] == 'mviewed' ) {
}
else{
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'posts_per_page' => 9,
'meta_query' => $meta_queries,
'paged' => $paged
));
}
?>
<div class="paginate_nav">
<?php wp_pagenavi(); // use the page navi function ?>
<div class="sort_nav">
<?php contrPaginationLinks( $sortOrder ) ?>
</div><!--sort_nav-->
</div><!--paginate_nav-->
<?php
if( $_GET['sort'] == 'mviewed' ) {
}
else{
if (have_posts()) : while (have_posts()) : the_post();
$item = metadata($post->ID);
$containsVideos = false;
foreach ($item['cat'] as $value) {
if (strpos($value->cat_name,'Videos') !== false) {
$containsVideos = true;
}
}
?>
<div class="story-container" >
<div class="story_left">
<div class="story_image">
<input type="hidden" name="vidID" value="<?php echo $item['media_link']; ?>" />
<div class="about_latest_image <?php echo $item['media_link']; ?>">
<a href="<?php echo $item['link']; ?>">
<?php
print_thumbnail($item['featured_thumb'],"thumbnail", $item['youtube_link'], $item['vimeo_link'], $item['media_link']);
?>
<?php if($containsVideos == true){echo '<span class="videoIndicator"></span>';} ?>
</a>
</div>
</div>
<?php if($_GET['sort'] == 'date'){ ?>
<div class="story_view">
<?php echo $item['date']; ?>
</div>
<?php } ?>
</div>
<div class="story_title">
<a href="<?php echo $item['link']; ?>" title="<?php echo $item['title']; ?>">
<span class="story_title"><?php echo $item['title']; ?></span>
</a>
</div>
<?php if(isset($item['custom_description']) && $item['custom_description'] !="") {
?>
<div class="story_description"><?php echo $item['custom_description']; ?></div>
<?php
}
?>
<div class="story_content"></div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1><?php _e("No Posts Yet", "hooplahatheme"); ?></h1>
<p><?php _e("Sorry, What you were looking for is not here.", "hooplahatheme"); ?></p>
<?php endif;
} // end display else default
echo '</div></section>';
//
// reset query after display is done
//
wp_reset_query();
?>
<footer>
</footer> <!-- end article footer -->
</div> <!-- end #main -->
Update
It turns out that there is a 302 redirect occurring which is what I am trying to find out the next step.
Christopher's answer probably works for most people.
But..
If you want to stop the redirect from also affecting /pagename/page/1, this will help:
add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2);
function my_redirect_canonical($redirect_url, $requested_url) {
$do_redirect = true;
if(preg_match('/page/',$requested_url)){
$do_redirect = false;
}
return $do_redirect;
}
Found here.
So for anyone with a similar question the answer is simple. You can't paginate single post pages by default in wordpress. It will just redirect back to the root URL of the page. What you need to do to stop this is add this to your themes functions.php
add_filter('redirect_canonical','pif_disable_redirect_canonical');
function pif_disable_redirect_canonical($redirect_url) {
if( is_singular() && in_category('PLACE CAT ID HERE') ) {
$redirect_url = false;
}
return $redirect_url;
}
for more info on this you can look here http://wordpress.org/support/topic/home-pagination-page2-redirect-to-a-post
I really hope you can help out here.
I'm creating a theme for a client and I have created a custom post type called 'Testimonials' and now I would like to show the testimonials on the home page but I'm having trouble outputting the data for the meta information.
I have created a function in my functions.php file called 'show_testimonials' and I'm calling that in my index.php file (I haven't separated everything in to their constituant parts yet, e.g header.php, footer.php etc). This function is meant to show the posts and meta information from the 'Testimonials' custom post type but it doesn't.
I can see that I am pulling the correct meta data in to my '$meta' variable.
Below is the code for the 'show_testimonials' function.
function show_testimonials() {
$loop = new WP_Query(
array(
'post_type' => 'shv_testimonials',
'order_by' => 'ID',
)
);
if ($loop->have_posts()) {
$output = '<ul class="testimonial-list">';
while($loop->have_posts()) {
$loop->the_post();
$meta = get_post_meta(get_the_id(), '');
print_r($meta);
$output .= '
<li>
<a href="' . get_permalink() . '">
' . get_the_title() . ' | ' .
$meta['shv_testimonial_author'][0] . '
</a>
</li>
';
}
}
return $output;
}
Below is my index.php file.
<!DOCUMENT html>
<!--[if IE 6]>
<html id="ie6" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 7]>
<html id="ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html id="ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 6) | !(IE 7) | !(IE) ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta charset="<?php bloginfo('charset');?>" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>
<?php
global $page, $paged;
wp_title('«', true, 'right');
bloginfo('name');
?>
</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if ( is_singular() && get_option('thread_comments')) wp_enqueue_script('comment-reply'); ?>
<?php wp_enqueue_script('jquery'); ?>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page">
<header id="masthead" role="banner">
<div id="header-strip">
<nav id="secondary-navigation" role="navigation">
<?php wp_nav_menu(array(
'menu' => 'Secondary Navigation',
'container' => false
)); ?>
</nav>
<?php get_search_form(true); ?>
</div>
<div id="branding-nav">
<?php
if (is_front_page()) { ?>
<div id="logo" role="banner">
<img src="<?php echo bloginfo('template_directory') . '/images/logo.png'; ?>" alt="<?php bloginfo('name'); ?>" />
</div>
<?php } else { ?>
<div id="logo" role="banner">
<img src="<?php echo bloginfo('template_directory') . '/images/logo.png'; ?>" alt="<?php bloginfo('name'); ?>" />
</div>
<?php }
?>
<nav id="primary-navigation" role="navigation">
<?php wp_nav_menu(array(
'menu' => 'Primary Navigation',
'container' => false
)); ?>
</nav>
</div>
</header>
<div id="content">
<?php
if(is_front_page()) { ?>
<div id="feature">
<section id="introduction">
<?php
echo "<h1 class='title'>" . $options['shv_introduction_heading'] . '</h1>';
echo "<p class='short-description'>" . $options['shv_introduction_short_description'] . '</p>';
?>
<nav id="call-to-action" role="navigation">
<ul>
<li id="book-now">
Book Now
</li>
<li id="learn-more">
Learn More
</li>
</ul>
</nav>
</section>
<section id="gallery">
</section>
</div>
<?php } else { ?>
<section id="entries">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="main">
<header>
<aside class="post-image">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
} else { ?>
<img src="<?php echo get_bloginfo('template_directory') . '/images/no-image.png'; ?>" title="<?php the_title(); ?>" />
<?php }?>
</aside>
<h1 id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</h2>
<time datetime="YYYY-MM-DD"></time>
</header>
<section class="post-content">
<p><?php echo get_the_excerpt(); ?></p>
Read More
</section>
<section class="meta">
<p><?php the_category(',') ?></p>
<p><?php the_tags(""); ?></p>
</section>
</article>
<?php endwhile; else: ?>
<div class="error">
<h2>Oooops!</h2>
<p>Sorry something went wrong! No posts matched your criteria. Please try again.</p>
</div>
<?php endif; ?>
<?php posts_nav_link(' ⏼ ', __('« Newer Posts'), __('Older Posts »')); ?>
<aside role="sidebar">
<h2>Some Widget in The Sidebar</h2>
</aside>
</section>
<?php } ?>
</div>
<footer role="foottext">
<div id="footer-top">
<section id="social">
<div id="twitter">
<?php show_tweets(); ?>
</div>
<div id="share">
<h2>Share</h2>
<div id="icons">
<a href="http://twitter.com/home?status=Shiverschool Theatre in Education+http://www.shiverschool.co.uk/" title="Tweet About Us">
<img src="<?php echo get_bloginfo('template_directory') . '/images/twitter-share-icon.png'; ?>" alt="Tweet About Us" />
</a>
<a href="http://www.stumbleupon.com/submit?url={http://www.shiverschool.co.uk}&title={Shiverschool Theatre in Education}" title="Recommend us on StumbleUpon">
<img src="<?php echo get_bloginfo('template_directory') . '/images/stumbleupon-share-icon.png'; ?>" alt="Recommend us on StumbleUpon" />
</a>
<a href="http://digg.com/submit?url=http://www.shiverschool.co.uk/" title="Digg Us">
<img src="<?php echo get_bloginfo('template_directory') . '/images/digg-share-icon.png'; ?>" alt="Digg Us" />
</a>
<a href="http://www.facebook.com/sharer.php?u=http://www.shiverschool.co.uk&t=Shiverschool Theatre in Education" title="Recommend us on Facebook">
<img src="<?php echo get_bloginfo('template_directory') . '/images/facebook-share-icon.png'; ?>" alt="Recommend us on Facebook" />
</a>
<a href="https://plusone.google.com/_/+1/confirm?hl=en&url=http://www.shiverschool.co.uk&title=Shiverschool Theatre in Education" title="Recommend us on Google+">
<img src="<?php echo get_bloginfo('template_directory') . '/images/google-share-icon.png'; ?>" alt="Recommend us on Google+" />
</a>
</div>
</div>
</section>
<section id="testimonials">
<div id="testimonial">
<?php show_testimonials(); ?>
</div>
<div id="mascot">
<img src="<?php echo bloginfo('template_directory') . '/images/mascot.png' ?>" alt="Shiverschool Mascot" />
</div>
</section>
</div>
<?php wp_footer(); ?>
</footer>
</div>
</body>
</html>
Here is the full 'functions.php' file.
<?php
// Add JavaScript files
function add_scripts() {
wp_enqueue_script('modernizr_script', get_template_directory_uri() . '/js/modernizr.js', __FILE__);
wp_enqueue_script('global_functions_script', get_template_directory_uri() . '/js/global-functions.js', __FILE__);
}
add_action('wp_enqueue_scripts', 'add_scripts');
// Setup and load the theme options page and related code
require(get_template_directory() . '/inc/theme-options.php');
//Get theme options
$options = get_option('shv_theme_options');
// Add support for custom backgrounds
add_custom_background();
// Add support for post thumbnails and admin bar
add_theme_support('post-thumbnails');
add_theme_support('admin-bar');
// This theme uses wp_nav_menu() in two locations
if (function_exists('register_nav_menus')) {
register_nav_menus(array(
'primary' => 'Primary Navigation',
'secondary' => 'Secondary Navigation'
));
}
/*
* Register custom post types
*/
//Testimonials Post Type
class SHV_Testimonials_Post_Type {
//Create construct function
public function __construct() {
$this->register_post_type();
$this->metaboxes();
}
//Register post type
public function register_post_type() {
$args = array(
'labels' => array(
'name' => 'Testimonials',
'singular_' => 'Testimonial',
'add_new' => 'Add New Testimonial',
'all_items' => 'All Testimonials',
'add_new_item' => 'Add New Testimonial',
'edit_item' => 'Edit Testimonial',
'new_item' => 'New Testimonial',
'view_item' => 'View Testimonial',
'search_items' => 'Search Testimonials',
'not_found' => 'No Testimonials Found',
'not_found_in_trash' => 'No Testimonials Found in Trash'
),
'query_var' => 'testimonials',
'rewrite' => array(
'slug' => 'testimonials',
),
'public' => true,
'supports' => array(
'title'
)
);
register_post_type('shv_testimonials', $args);
}
//Build metaboxes
public function metaboxes() {
//Add new meta boxes testimonial and testimonial author
add_action('add_meta_boxes', 'add_testimonial_meta_box');
add_action('add_meta_boxes', 'add_testimonial_author_meta_box');
//Run add_meta_box functions
function add_testimonial_meta_box() {
add_meta_box('shv_testimonial', 'Testimonial', 'testimonial', 'shv_testimonials');
}
function add_testimonial_author_meta_box() {
add_meta_box('shv_testimonial_author', 'Testimonial Author', 'testimonial_author', 'shv_testimonials');
}
//Create form elements and pull through any data associated with each meta box
function testimonial($post) {
$testimonial = get_post_meta($post->ID, 'shv_testimonial', true); ?>
<p>
<label for="shv_testimonial">Please enter your testimonial</label>
<textarea class="large-text" name="shv_testimonial" id="shv_testimonial" cols="50" rows="5"><?php echo esc_attr($testimonial); ?></textarea>
</p>
<?php }
function testimonial_author($post) {
$author = get_post_meta($post->ID, 'shv_testimonial_author', true); ?>
<p>
<label for="shv_testimonial_author">Please enter a testimonial author name and school, e.g. John Doe, St Ambrose Barlow</label>
<input type="text" class="widefat" name="shv_testimonial_author" id="shv_testimonial_author" value="<?php echo esc_attr($author); ?>" />
</p>
<?php }
//Save meta box input
add_action('save_post', 'save_meta_data');
function save_meta_data($id) {
if (isset($_POST['shv_testimonial'])) {
update_post_meta(
$id,
'shv_testimonial',
strip_tags($_POST['shv_testimonial'])
);
}
if (isset($_POST['shv_testimonial_author'])) {
update_post_meta(
$id,
'shv_testimonial_author',
strip_tags($_POST['shv_testimonial_author'])
);
}
}
}
}
add_action('init', 'register_testimonials');
function register_testimonials() {
new SHV_Testimonials_Post_Type();
}
function show_tweets() { ?>
<img src="<?php echo get_bloginfo('template_directory') . '/images/twitter-bird-icon.png'; ?>" alt="Tweets" />
<?php
//Get theme options
$options = get_option('shv_theme_options');
include_once(ABSPATH . WPINC . '/feed.php');
$username = $options['shv_twitter_username'];
$rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=' . $username);
if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity(1);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo $item->get_permalink(); ?>'>
<?php echo $item->get_title(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php }
function show_testimonials() {
$loop = new WP_Query(
array(
'post_type' => 'shv_testimonials',
'order_by' => 'ID',
)
);
if ($loop->have_posts()) {
$output = '<ul class="testimonial-list">';
while($loop->have_posts()) {
$loop->the_post();
$meta = get_post_meta(get_the_id(), '');
print_r($meta);
$output .= '
<li>
<a href="' . get_permalink() . '">
' . get_the_title() . ' | ' .
$meta['shv_testimonial_author'][0] . '
</a>
</li>
';
}
}
return $output;
}
?>
Here's a link to the development site where you can see that I'm outputting the correct meta data using 'print_r($meta);'. http://dev.garethdaine.com/shiverschool
I hope someone can point me in the right direction. Cheers in advance.
The output of show_testimonials is just not printed anywhere, try echo show_testimonials() in your template or echo $output; instead of return $output; in your show_testimonials function.