Wordpress - Three custom posts with the same slug - wordpress

I have three posts that have the same title and address, if I am logged in it displays my posts at all, but it logs out can not see them and shows me 404 if we can somehow read these posts?
i read post with this:
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part('templates/content', 'single');
?>
<?php endwhile; // end of the loop. ?>

I think your posts are private posts. Just edit a post from them and check at the right side of your content editor. There are few options, make this post public and then click on update.
Now check, your issue got resolved.
Go through this article for more info : http://en.support.wordpress.com/posts/post-visibility

Related

Angular + WordPress

I have a ticket sales form written in Angular. How can I insert this form on the main page of Wordpress site? May be with usingthe tag iframe or can there be better solutions for this task? Thank you for attention!
I think a best solution to this is to create a new page template (you can google it to get more accurate info), see what is page templates here.
Basically, you will create a new file on your theme root, with the prefix page-, e.g: page-tickets.php. And then the very first thing that must appear on your page is a comment,like this: // Template Name: Tickets Page. Your page will be something like this:
<?php
// Template Name: Tickets Page
get_header();
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Angular + Html codes here!
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<script>angular and js imports</script>
<?php get_footer(); ?>
With that, when you will create a new page in Pages -> New (or edit), in the right bottom side will be available an option to you to choose a page template, like this:
That's all, I hope it helps you.

Cant' Grab WordPress Built-in Posts Through Loop

Using WordPress 3.7.1 I am trying to display all Regular Post on my created page lest say TestPage. Here are the steps I took to do this:
1- Generate a Custom Page Template called:Test Page and loaded by following code
2- Generate a Page Called TestPage based on Test Page Template
after updating the page I am not getting any of Post on the page while I have already generated some!
<?php
/*
Template Name: Test Page
*/
?>
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title() ;?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, this page does not exist</p>
<?php endif; ?>
<?php get_footer(); ?>
he abouve code actually is loading the page whit title and content of the TestPage and not by Posts!Can you please let me know why this is happening?
You must understand the difference between post and page.
A page is associated with a template. Through code, you can lists posts or other pages using this page /template.
The above code will only display the Page data
You don't want to create many pages using the same tempalte in order to show different data with the same tempalte. Instead you create posts and give them a category.
Then you can fetch these posts and display them in the same way asthe test-page.
You can either use get_posts or wp_get_recent_posts.
Or, if you really want to list pages, use wp_list_pages.
Besides that, you should look at http://codex.wordpress.org/Pages and http://codex.wordpress.org/Posts

Password protecting not working for custom post type single-template.php? - Wordpress

I have created a custom post-type 'Clients' where admin user can create new clients, add pictures and details to post, then password protect the page so only a particular client can access the content.
For displaying content of this post-type on the front end, I'm using a single-clients.php template. It displays the content perfectly, but the password protect function does not display the form and hide the content, even if I'm in a different browser, cache cleared/logged out of Wordpress (viewing it as a regular end-user would).
What might I be doing wrong here?
<?php get_header(); ?>
<div class="container-client">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Display all fields and content for post-type
<?php endif; ?>
<?php endwhile; else: ?>
<div class="alert-box error">Sorry, this page no longer exists :( — Back to home</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
This is roughly how my single-clients.php page is setup. Is there any way to manually display the password function so that when end-user visits page, the content is hidden and password form is displayed?
I had exactly this problem and after some trying and reading the codex I came up with this solution:
<?php
add_filter('single_template', function($single_template) {
global $post;
if ($post -> post_type == 'your-custom-post-type') {
if (!post_password_required()) {
$single_template = 'path-to-your/single-your-custom-post-type.php';
}
}
return $single_template;
});
?>
This way the page is only rendered in the custom sinlge view after entering a password, if it is password protected.

query_posts does not return old posts?

I'm using query_posts on my home page to fetch articles from multiple post types. I'm using following code to do so.
<?php query_posts( array('post_type' => array('post','page','custom_post1','custom_post2','custom_post3','custom_post4','custom_post5','custom_post6')));
if (have_posts()) : while (have_posts()) : the_post(); // begin the Loop ?>
/*html code goes here*/
<?php endwhile; endif; ?>
It fetches the posts rightly, but the problem is: it does not fetch old posts. So for example I have 1 post and its publish date is 02/july/2012, this post won't be displayed on my home page. But as soon as I update the date to 02/Aug/2012 it starts showing up on Home page.
So is there any code I can add in query_posts that will enable older posts to be fetched too.
Wordpress by default fetch 10 posts or number of posts set by user from admin.
query_posts accept argument that return number of record.
query_posts( 'posts_per_page=5' );
query_posts( 'posts_per_page=50' );

wordpress conditional statement for home page

I am developing a wordpress blog theme, which shows the posts on the homepage. I am trying to show some text ONLY on the homepage, and not on page 2,3 ,4 and so on of the blog posts. The code below shows the text on all blog pages:
<?php
if (is_front_page()) {
?><p>TEST FRONT PAGE</p>
<?php
} ?>
How do I show this ONLY on the front home page (page 1, not pages after 1)?
ANSWER FOUND IN COMMENT BELOW
Instead of declaring an additional variable and checking it you can access the global in wp_query with is_paged.
<?php if (is_home() && !is_paged()) : ?>
Your front page content.
<?php endif; ?>
Or if you have a static post as the front page with its own sub pages you can use:
<?php if (is_front_page() && !is_paged()) : ?>
Your static front page content.
<?php endif; ?>
To target just the first page of the static post.

Resources