WordPress Posts from category won't display - php

I use a plugin called "Custom Content Type Manage"
this allows me to create a new content type which essentially mimics posts (all done in the name of 'user friendly')
This aside, I wrote the following:
<h2><?php single_cat_title( '', true ); ?></h2>
<p>
<?php
$page_id = '5536';
$page_data = get_page($page_id);
print apply_filters('the_content', $page_data->post_content);
?>
</p>
<p>
<?php
$category = get_the_category();
$category_id = $category[0]->cat_ID;
print category_description( $category_id );
?>
</p>
<div class="category-list">
<?php wp_nav_menu(); ?>
</div>
<ul class="leaders-container">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<li class="leader-container">
<?php
$image = get_custom_field('leader_image:to_image_array');
$url = get_custom_field('website_url:raw');
print "<img class='leader-image' src='".$image['0']."'>";
?>
<h2>
<?php the_title(); ?>
</h2>
<?php
print "</h2>";
the_content();
if($url != "#") {
print "<a class='website-button' href='".$url."' target='_blank'>Visit Website</a>";
}
?>
</li>
<?php endwhile; endif;?>
What this was doing, was getting the info from the category, and listing all the posts assigned to the category.
In this case, a post was labeled as a "Leader" and a category was their "congregation", so it was listing all the leaders assigned to the congregations.
This is an example of what it should look like
http://www.ubmsonline.org/?leader=rabbi-binyamin-sheldrake
However, this only works as it is a direct link from the posts in question
The category on the otherhand, which was working, and did list as many leaders assigned to the category, has now stopped working.
http://www.ubmsonline.org/category/ubms-leaders/
As you can see though, its pulling everything across correctly, category description, category title etc, but its just now not showing the posts.

fixed!
It was to do with a setting that changed on the "Custom Content Type Manager" plugin im using. After alot of research, i stumbled upon the exact problem on the "issues" section of the plugin's FAQ's page.
https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=594
Hopefully this might help others.
In wp-content/plugins/custom-content-type-manager/loader.php the filter mentioned below might be commented, so if you uncomment this add_filter this bug will fix.
// Enable archives for custom post types
add_filter('request', 'CCTM::request_filter');
Thanks again for every one's help.
Andrew

Related

Get post from a single category with have_posts () WordPress

I am showing the last post of a blog on an external website that I am developing out of wordpress.
<?php
//Include WordPress
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
//Define quantos posts serão exibidos
query_posts('showposts=3');
?>
<?php while (have_posts()): the_post(); ?>
<li>
<h4><?php the_title(); ?></h4>
<span><?php the_time("d/m/Y"); ?></span>
<?php the_category_ID(); ?>
<?php the_content(); ?>
<div>
« Leia Mais...
</div>
</li>
<?php endwhile;?>
The point is that the blog is separated into two categories and I would like to display only one of them.
Link where I got those functions.
http://codex.wordpress.org/Template_Tags
When you query posts, you can add the conditions for categories as well, like this:
query_posts('showposts=3&cat=CAT_ID'); //replace CAT_ID with the category ID that you want
Since you mentioned that you wanted to show the latest posts, you might need to do this:
query_posts('showposts=3&cat=CAT_ID&orderby=date&order=DESC');

ARCHIVE.PHP SHOWS ONLY ONE POST PER CATEGORY

I realized my website (www.inunfuturoaprile.it) with a minimal Wordpress theme that does not include the category.php template. I have created the template by me: the goal was to get pages that display a list of the posts belonging to a specific category. Unfortunately, due to my scarce knowledge of php, the code does not seem to work properly: I only see one post per category (e.g. https://www.inunfuturoaprile.it/politica/).
Here's the category.php file code:
<?php
/**
* Template di Categoria
*/
get_header(); ?>
<div id="content">
<?php
// Check if there are any posts to display
if ( have_posts() ) : ?>
<?php
// Since this template will only be used for Design category
// we can add category title and description manually.
// or even add images or change the layout
?>
<h1><strong><?php single_cat_title(); ?></strong>: Elenco Articoli</h1>
<div class="entry">
<?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?> // <small><?php the_time('j F Y') ?></small>
<?php endwhile; // End Loop
else: ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Someone can help me? Thank you :)
I think your posts_per_page parameter is set to 1.
You can see other posts using pagination:
https://www.inunfuturoaprile.it/politica/page/2/
https://www.inunfuturoaprile.it/politica/page/3/
Check it on Settings->Reading page ( /wp-admin/options-reading.php), parameter "Blog pages show at most"
But it also can be set up somewhere in the theme code.
Changing it may affect your main page - since the main page shows only one post too.
So you can change it only on category.php page. Add this after get_header():
get_header();
global $wp_query;
$wp_query->set('posts_per_page', 10);
// or this - if you need no pagination at all:
// $wp_query->set('nopaging', true);
$wp_query->query($wp_query->query_vars); ?>

Static wordpress page linking to posts

Hi I am trying to making my static wordpress page seen here
Link to the posts that are shown. However they are just linking to the file directory in the browser and not the post.
It was working before where it would just link to the post in a wordpress theme but now that doesn't even work.
I haven't touch the code in a week I left it in the state as mentioned above, where it would link but just to the wordpress theme.
Here is the code I use to get the information to the static page from wordpress -
<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
<article>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
<hr>
</article>
<?php endwhile; ?>
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<nav class="prev-next-posts">
<div class="prev-posts-link">
<?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
</div>
</nav>
<?php } ?>
<?php else: ?>
<article>
<h1>Sorry...</h1>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
</article>
<?php endif; ?>
Basically what I am trying to do is get it so when I click on the post it takes me to that post. Not to the file directory.
Any help is appreciated. Thank you.
I'm using xubuntu 16.04_LTS incase that has anything to do with compatibility in wordpress.
I have permalinks setup as shown
If all you want is the links to work . . .
http://auroraservers.org/MainSite/?p=38 ---fails
http://auroraservers.org/MainSite/wordpress/?p=38 ---works
That works and could be adjusted in the permalinks custom area. If you want that URL to be different, you're dealing with htaccess changes.
While not beautiful, you could replace the_permalink(); with
$id = get_the_ID();
$url = 'http://auroraservers.org/MainSite/wordpress/?p='.$id;
try to rename Index.php as index.php. It seems like Wordpress can't find index.php as a template for the post and therefore the system redirects you to the file directory since it can't find any of the possible template files.
Addition: Since your "Index.php" seems not to include code for the display of single posts, you might want to set up a file "single.php" as a template for single posts. But nevertheless, Wordpress will try to use index.php in many situations - always when the actual template file for a particular post type can't be found, like archive.php, page.php and many others...
So it might be a good idea to create a "regular", all-purpose index.php, rename your static page to something else, for example to front-page.php and define t as your starting page.
I seem to have fixed the issue I have been having. Thanks for all the replies.
Incase someone needs to know what I have done.
I went into mysql and dropped the database and recreated it. Must of gotten corrupted somehow.

Retrieve posts by category name issue in WP Query

So I've created a custom page template for my "Topics" Page.
What I want to do is add in some PHP to the custom page template my Topics page uses, to retrieve permalinks for the 3 most recent posts from a chosen category.
E.g.
(From post category 1)
--> Permalink for post 1
--> Permalink for post 2
--> Permalink for post 3
My code so far is as follows:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<ul>
<?php
$category_posts = new WP_Query('cat=consumer-trust&showposts=3');
while ($category_posts ->have_posts()) : $category_posts->the_post();?>
<li>
<a class="yourclass" href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> </a></li>
<?php endwhile; ?>
The problem, however, is that changing the cat in the WP_Query doesn't seem to make any difference. I've tried numbers and category names, and neither works.
Can anybody advise? This code will appear three times on the intended page, for three different categories.
use
query_posts( array ( 'category_name' => 'cat_name','meta_key'=>'_pr_date', 'orderby' => 'meta_value','order'=>'DESC') );
Thanks for all the help, I've managed to find an answer:
<?php global $post; // required
$args = array('category' => 18); // include category 18
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
// put here what you want to appear for each post like:
//the title:
the_title();
endforeach;
?>

Pulling Wordpress Categories Dynamically

I hope someone will be able to help me. I already know how to pull the most recent post in wordpress using this code:
<?php query_posts('posts_per_page=1'); ?>
<?php while (have_posts()): the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
<?php endwhile;?>
This works fine, but I want to extend this functionality. I want to be able to pull posts based on a specific category. For example, the site I'm working on has a page called "Social Media" with information on the topic. It also has a blog category of the same name. I want to know how I can pull the posts from the Social Media section of the blog to the informational Social Media page (and so on - we will have about 10 more categories which will also need their related posts).
Any help would be much appreciated! Thank you!
wp_list_categories can help you in this regard. Code will be similar to the following one:
<ul>
<?php wp_list_categories('orderby=books&include=2'); ?>
</ul>
Detail can be found here. http://codex.wordpress.org/Function_Reference/wp_list_categories
You could do it with code like this:
<?php $social_media_id = get_category( 'social-media', ARRAY_A ); ?>
<?php $social_media = query_posts( 'posts_per_page=1,category=' . $social_media_id['cat_ID'] ); ?>
<?php while (have_posts()): the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
<?php endwhile; ?>
For the get_category part, you could substitute the hard-coded social-media with the $pagename (if it's the same as the category's name).

Categories