Display single custom post - wordpress

i have custom post type events. i want to display content from single post and using single-events.php .
The code in single-events.php is
<?php get_header(); ?>
<?php $args = array( 'post_type' => 'events',
);
$loop = new WP_Query( $args );
if($loop->have_posts()):while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_content( ); ?>
<?php endwhile;endif; ?>
<?php get_footer(); ?>
But its displaying the content from all of the posts of custom type- 'events': how do i display the post from just single post

The events post object should already be in $wp_query - you don't need to reinitialise it. Just process it with the standard WordPress loop. Something like (untested):
<?php get_header();
if(have_posts()):while ( have_posts() ) : the_post();
the_content( );
endwhile;endif;
get_footer(); ?>

List and single event for same file call.
see the step:
you can change structure for single event so go hear
<?php
/**
* Template Name: Event page
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="page_content">
<div class="content_wrapper">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
endwhile;
?>
</div>
</div>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_footer();
if(get_post_type()=='tribe_events' && is_single() ) {
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
} else {
//for list code
}

Related

ACF Group field not displaying on the front end

I have created a group field in ACF to display on posts, pages and custom post type. Please see below screenshots.
And here's the code I'm trying for front-end.
<?php $footerCTA = get_field('footer_cta');
echo $footerCTA['title']; ?>
The code above doesn't output anything on the front-end. Am I missing here something?
Thanks.
try this:
if( have_rows('footer_cta') ):
while( have_rows('footer_cta') ) : the_row();
?>
<p><?php the_sub_field('title'); ?></p>
<?php
endwhile;
endif;
?>
Try using.
echo the_field('footer_cta');
Other Way.
You can do this by adding a second parameter to the get_field or the_field functions. This second parameter will contain the correct ID which can be found using get_option('page_for_posts') like so
<h1><?php the_field('footer_cta', get_option('page_for_posts')); ?></h1>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->

How to fix pagination link to page 2 wordpress?

Hi all I am a new of wordpress I have problame with pagination, I used plugin Wp-pagnavi ,When I click link to page 2 it same as page 1,How to to fix it.
You can see it at
http://westecmedia.com/?page_id=758
And this my code in page-event.php
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; endif; ?>
<?php wp_pagenavi(); ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please :(
Include paged, documentation: https://codex.wordpress.org/Pagination
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
endwhile;
wp_pagenavi();
wp_reset_query(); // Restore global post data
?>
Also don't use query_posts to fetch data in WordPress, consider using https://codex.wordpress.org/Class_Reference/WP_Query.
Please ask WordPress related question here: http://wordpress.stackexchange.com
I hope this helps.

How to take off title from wordpress page loop?

Below is my wordpress loop and i have tired to take-off the Page title but its not happning.
Please suggest me the correct loop.
<div class="single-full-width-container single-page-header-container">
<header class="container">
<?php the_title( '<h1 class="single-page-heading">', '</h1>' ); ?>
<ul class="single-page-breadcrumbs">
<?php
if(function_exists('bcn_display') && !is_front_page())
{
bcn_display();
}
?>
</ul>
</header>
</div>
<div class="container">
<div class="row">
<main role="main" class="shortcode-container span12">
<div class="row">
<div class="span12">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
</div>
<!-- .entry-content -->
<?php endwhile; ?>
</div>
</div>
</main>
</div>
I have tried with other loop without the "title" tag but its still coming at top.
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
Remove the line
<?php the_title( '<h1 class="single-page-heading">', '</h1>' ); ?>
I think you're not editing the proper file.
There is a line in your file:
<?php get_template_part( 'content', 'page' ); ?>
This part is intended to import the content-page.php file as far as I know. Maybe this file puts the title on the top of the article. Try to edit that file if you find anything like that. If there is no content-page.php it falls back to import content.php.
(For more details check this: http://codex.wordpress.org/Function_Reference/get_template_part )
If I'm right the part of the file you cited above makes no effect after the second appearance of this line:
<?php while ( have_posts() ) : the_post(); ?>
Because the first appearance looped through the whole collection of the posts so the have_posts() function returns false after that. So the whole section until <?php endwhile; ?> (lines 22-33) is always skipped.
I hope I was right and could help you with your task :)

Wordpress More tag is not working on home page

I'm currently working on integrating wordpress with my website, but I'm hitting a wall here.
I need the initial blog page(basically just the index.php of WP) to pick up the <!--more--> quicktags, but I can't seem to get it to work.
I've followed the WP Codex, but that didn't help me at all.
So here's part of the template file: content.php
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
the_excerpt();
?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<div class="bthumb2">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(array(220, 130));
}
?>
</div>
<?php
the_content("READ MORE");
?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'tinfoilhats' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
But it just keeps displaying the <!--more--> tag in the posts once I load the page.
I've tried it with the global $more thing, but that didn't work for me.
<?php while ( have_posts() ) : the_post(); ?>
<?php
global $more;
$more = 0;
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
So what am I doing wrong?
Your global $more example looks good, and almost follows the recommendation on the documentation page applicable (the global $more line itself is supposed to be outside "the loop" - before while ( have_posts() ) - leaving the next line where it is.)
However, I couldn't get this to work on my own blog (using a a child theme of Coraline) until I moved both lines to before "the loop". Starting with your code, I'd suggest something like this:
<?php
global $more;
$more = 0;
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

Wordpress - display certain categories on homepage

I have been trying to alter my current code, but it makes no sense to me (it doesn't do what I was told it does). All I want to do is only display posts with category 13 on my homepage and I want to be able to add multiple categories to a post.
Post 1 (Category 13 and 1) = displayed on homepage
Post 2 (Category 13 and 4 and 5) = displayed on homepage
Post 3 (Category 6 and 1) = not visible on homepage
Post 4 (Category 2) = not visible on homepage
This is my current code to only show category 13 on my homepage, if another category is added to the post it won't be displayed at all.
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
if (is_home()) {
query_posts("cat=-6,-4,-1,-11");
}
?>
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => 13,
'posts_per_page' => 5,
'paged' => $paged);
query_posts($args);
?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Geen berichten beschikbaar', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Helaas, er zijn nog geen gearchiveerde berichten in deze categorie. ', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
You're looking way too hard at this code. You don't need to exclude anything, you just need to include cat 13, which will include everything that is in cat 13; even if it is in other categories as well. Just run a regular WP_Query() like so:
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
if (is_home()) {
// The Query
$the_query = new WP_Query("cat=13, paged=".get_query_var('paged'));
}
?>
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Geen berichten beschikbaar', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Helaas, er zijn nog geen gearchiveerde berichten in deze categorie. ', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
(had to add a few charachters or I could not edit, sorry :P)
Try this...
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=6&cat=13'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Your stuff goes here...
<?php endwhile; ?>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
Try this code
<?php
global $post;
if (is_home()) {
$args = array( 'numberposts' => 5, 'category' => 13 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content( 'Continue reading <span class="meta-nav">ยป</span>); ?>
</div>
<?php endforeach;
}
?>
This will display the title and content. If you want additional information like date, author, category, tag etc, you may have to use other template tags. Also if you want to style these differently, then you have to use appropriate CSS.

Resources