Permalink from WP_Query posts not displaying posts content - php

I am creating a custom WordPress Theme from scratch and I want to display some news from a certain category. I am doing it with the following code:
wp_reset_query(); $args = array(
'type' => 'post',
'posts_per_page' => 3,
'category_name' => 'oportunidades' );
$opp = new WP_Query($args);
while($opp->have_posts()) : $opp -> the_post(); ?>
<h4> <?php the_title(); ?></h4>
<?php endwhile; ?>
The list of news are being displayed correctly, but when I click the link to a certain post, it will change the URL of the page, but not display the contents of the post. If I echo the title, contents, and hyperlink of the post, it will echo the correct information.
How can I fix this, so when I click the post it shows the contents of the post?
*note: I have created a file named content.php, but it has no code inside. Can that be the problem?

Related

How to display all posts with the same title in wordpress single.php file

I have an anime website in WordPress where I add episodes as posts.
I'm using a theme that i created by myself, what i want is to display the list of episodes of the anime that the user is watching by looping through the posts with the same title to display them all using PHP. I tried a lot of solutions but none of them worked.
In brief, I want to display posts with the same title to make a list of episodes
This is one of the solutions that i tried and didn't work.
<div class="episodes">
<?php
$EpisodesList = new WP_Query('post_title='the_title()'');
if ($EpisodesList->have_posts()) {
while(have_posts()) {
the_post();
echo the_title( );
}
}
?>
</div>
You must get the post type 'EpisodesList' in your WP Query. WP_Query is a class used in WordPress theming that accepts a variety of parameters to request and fetch posts around those parameters. The example below allows you to set a list of parameters, fetch the posts matching those parameters, and display the title and excerpt of the post on the website.
Code goes in your custom template file where you want to render the posts.
/**
* Setup query to show the ‘EpisodesList’ post type with ‘8’ posts.
* Output the title with an excerpt.
*/
$args = array(
'post_type' => 'EpisodesList',
'post_status' => 'publish',
'posts_per_page' => 8,
'orderby’ => 'title',
'order’ => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
print the_title();
the_excerpt();
endwhile;
wp_reset_postdata();

How can I show a certain post recognised by title on my archive page? - Wordpress

So I basically have some sort of list with certain menu items, I want the top menu item to show on the archive page so it doesn't look empty. The post is always on top so I think the easiest way is to pick it out by the title of the post. But I have no idea how i can do this.
<?php
$query = array (
'post_type' => 'results',
'order' => 'DESC'
);
$queryObject = new WP_Query($query);
if ( $queryObject->have_posts() ): while ( $queryObject->have_posts() ): $queryObject->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; endif; ?>
This is my code basically and you can see that it posts the titles from all posts in links so that is is some sort of menu, on click it shows the content from the post.

Show a single post on other template/page

Working on a site, and I need to have a separated template/page for showing just that one post.
On the home page (index) Ill loop through my categories and showing just a part of them - events - news - references.
Like this:
<?php
$query = new WP_Query( array( 'category_name' => 'Events' ) );
if ($query->have_posts())
{
while ($query->have_posts()) : $query->the_post();
$haveEvents = true;
if ($eventCount < 3) {
$eventCount++;
?>
<div class="event-tile">
<div class="event-tile-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_time('F jS, Y'); ?></h4>
Lees meer
</div>
</div>
<?php
}
endwhile;
}
Every section has a read all and read specific item button:
I already found out how to display all posts within a category on a separated page named: page-posts.php
On page-posts.php I simply check on which page I am and depending on which page, make a query to show the posts within a specified category
$query;
if (is_page('events')) {
$query = new WP_Query( array( 'category_name' => 'Events' ) );
}
elseif (is_page('news')) {
$query = new WP_Query( array( 'category_name' => 'News' ) );
}
if ($query->have_posts())
{
etc..
Now what I cant figure out (not even after spending like hours on google), how to show a single post from the home page (index.php), on a single-post page...
On the action buttons I use:
Lees meer
Which brings me back to the homescreen. (just started on Wordpress)
In a Wordpress theme single.php is used to display a post. If it does not exist it drops down to using your index.php
Try moving your page-posts.php to single.php
Maybe its better to use archive-events.php. You can make an archive for custom posts.
With that you can do: where events is your custom post-type. Then you land on the events archive page.
As far as i can see your problem is that the post is the global post (from your home). So maybe you can setup_postdata($post), or use the home_url('url') functions.

how to get the posts from my index page to someother pages(like blog) in WordPress

i am beginner to WordPress, i have created the index.php it automatically shows my posts.. but i wanna posts to show also in another php file like blog.php.. how can i retrieve the same posts which is shown in index.php.........
The scenario is, i am developing theme for http://themeforest.net show that i wanna make some features in my blog page like without sidebar, left sidebar, right sidebar... but my home(index.php) contains posts.. whenever i starts new page with same coding(like blog.php), it doesn't show the index.php 's posts..
This sample piece of code retrieves 3 posts from categpry id 4
<?php
$args = array( 'numberposts' => 3, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 4 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
$a= get_the_date();
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php endforeach; ?>
Refer the WordPress documentation http://codex.wordpress.org/The_Loop
it contain different example how to display post include or exclude post from specific categories etc..

Wordpress (Wordpress popular posts plugin) query

Can I use:
<?php
if (function_exists( 'wpp_get_mostpopular' )) {
wpp_get_mostpopular('range=weekly&order_by=views&limit=8');
}
?>
Inside custom template (inside query posts) to make query with own template output:
<?php query_posts(????????); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="myclass">
<?php echo get_the_post_thumbnail( $post_id, 'thumbnail'); ?>
</div>
Please help me with this, so I don't have to edit plugin and plugin's css while I have my ready just to query posts by this plugin.
Thanks.
Plugin: http://wordpress.org/plugins/wordpress-popular-posts/
#alen imeko as far as i have understoody your requirment, why you need this plugin, you just need to show the most popular post where ever you need to, You just need to set the post to sticky and call the sticky post using the same query post method then it will automatically render your specified post at the respective place.
For this just go to post to make it sticky, at the top above the publish/update button you will see an option visibility click the edit part of it and you will the options will slide down check the checkbox having text Stick this post to the front page and after that you just need to perform query.
$args = array(
'post__in' => get_option('sticky_posts'),
'posts_per_page' => 20,
'orderby' => 'title',
'post_date' => 'DESC',
'cat' => your category id
);
query_post($args);
?>
Then you need to simply use the while loop for that the same way you do in wordpress.

Categories