I am using the all-in-one event calendar plugin and it provides shortcodes for the user to enter into a post and then it will display the event information. The shortcode is [ai1ec events_limit="3"]. My Loop is below.
<?php
$eventArgs = array(
'category_name' => 'events_home'
);
$eventQuery = new WP_Query( $eventArgs );
if ($eventQuery->have_posts()) : while ($eventQuery->have_posts()) : $eventQuery->the_post();
?>
<?php the_content(); ?>
<?php
endwhile; endif; wp_reset_postdata();
?>
The output result only shows one event and then three dots "...", which I am assuming means the content the being shortened. Is there a way to NOT limit the_content(); I have tried:
<?php echo get_the_content(); ?>
But that only prints out the shortcode text.
Summary: Is there a way to NOT limit the_content();
Is your default setting shows content summary?
In this page from Wordpress Developer I've found this:
Overriding Archive/Single Page Behavior
If the_content() isn’t working
as you desire (displaying the entire story when you only want the
content above the Quicktag, for example) you can override
the behavior with global $more.
//If you need to display all of the content:
// Declare global $more (before the loop).
global $more;
// Set (inside the loop) to display all content, including text below more.
$more = 1;
the_content();
Related
I need the option to build a page showing all posts of a specific category.
Showing all posts of a category can be done out-of-the-box by wordpress, I know. But I need the possibility to put some information about all those posts.
I know there's a plugin called "List category posts" (http://wordpress.org/plugins/list-category-posts/). It works but it's only showing the links to the posts. I need the full posts (like they are shown on the "blog page").
If you need to "do something" to results, look at
query_posts
via http://codex.wordpress.org/Function_Reference/query_posts
Here is a sketch that I think leans towards your needs using a custom loop. This can be inserted as needed via simple logic in your template:
// this sets up the filter parameters for a category id some_cat_id sorting asc
$args = array(
'cat' => $some_cat_id,
'order' => 'ASC'
);
// The query is applied via a conditional
if($some_conditional) { // for what ever reason we use the filter+args
query_posts( $args );
// this is also an opportunity to "do stuff" before the loop/output
}
// The Loop (simple example)
while ( have_posts() ) :
the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
As a long time WP user I avoid plugins at all costs in preference of writing sustainable code. Plugins are a point of failure and some of the biggest plugin factories out there are nothing but security issues wrapped in sugar.
Custom loops via conditionals using query "filtering" is amazing and this pattern can be extended to category, search, tags, and meta key:value pairs.
Additionally, by understanding the loop the formatting and output can be controlled in a manner that is easy to sustain. Some of the plugin logic is horrid and very inefficient, so always investigate any and all plugins when performance and security are important.
Here's what I find to be the most simple way to do this:
<?php query_posts('cat=25&showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
//You can change up the format below any way you'd like.
<li class="homeblock" style="max-width:400px;">
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div class="contentbox"><?php the_excerpt(); ?> </div>
</li>
<?php endwhile; endif; ?>
You can add this to a theme template file and all you need to change is the category id to the category you are trying get posts from. For example if your category id is '114' and you would like to show 9 posts it would look like the following:
<?php query_posts('cat=114&showposts=9'); ?>
If you need to add more info to the posts you should consider using custom fields to do that. Check out the plugin called Advanced Custom Fields.
Here is an example of a custom field being used in a loop:
<?php query_posts('cat=25&showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li class="homeblock" style="max-width:400px;">
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div class="contentbox"><?php the_excerpt(); ?> </div>
<?php $article_link=get_post_meta($post->ID, 'article-link', true);?>
<?php if ( $article_link ) : ?>
<?php else : ?>
<?php endif; ?>
</li>
<?php endwhile; endif; ?>
In the above example, if the custom field 'article-link' has a value, then that value (a URL) is used as the href in a link instead of the permalink of the article.
Hope I have helped!
I am using wp_list_pages to create a submenu on a page and child page.
All working fine
My menu looks like
Parent, page title is Hello
Child,
Child,
Child,
etc
I am trying to find a way to dynamically change the Page title on output.
In my example above, I would like my Parent page to display GoodBye instead of Hello.
You might wander why I don't just rename my page to Goodbye.
It is because the Page title , in my design, is displayed in 3 different format
- menu Header Hello displays Welcome (can change this via WP menu
- Page title display the correct title, ie Hello
I need my left menu to display Goodbye....
hope this makes sense for somebody
thx
Use a custom field on your page...let's call it sidebar_title.
Then, you'll need to convert your wp_list_pages code into a custom WordPress loop (there might be a way to use get_pages to do the same if you prefer that.
Here's some sidebar code to list the current page and it's child pages, replacing the_title(); with your sidebar_title if it exists. It's pretty ugly...the main point is to show you how to access custom fields.
<?php
//Get children of current page and display with custom fields.
//You will probably need to adjust this.
$args=array(
'post_parent' => $post->ID,
'post_type' => 'page',
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
?>
<ul>
<?php
// Print parent with sidebar_title, if it exists
$sidebar_title = get_post_meta($post->ID, 'sidebar_title', true);
if ($sidebar_title != ''){ ?>
<li><?php echo $sidebar_title;?></li>
<?php } else { ?>
<li><?php the_title(); ?></li>
<?php } ?>
<?php
// Print each child page with sidebar_title, if it exists
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php
$sidebar_title = get_post_meta($post->ID, 'sidebar_title', true);
echo $sidebar_title;
if ($sidebar_title != ''){ ?>
<li><?php echo $sidebar_title;?></li>
<?php } else { ?>
<li><?php the_title(); ?></li>
<?php } ?>
<?php endwhile; } ?>
</ul>
<?php wp_reset_query();?>
I've built a custom page.php template. Very simple, essentially:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php get_footer(); ?>
I've created a few pages, and if I visit their url, I just get the same page title.
I read up in the documentation, and it says to use the_title() and such only when in "the loop".
So presumably, I'm just being shown the first page in the "array".
Is there any way I get get the contents of a single page based on the url?
Edit: In fact, should I even need to do this? Refering to example templates, it looks like I'm doing everything right?
In my sidebar I was using a custom query.
This was called before trying to access the main page content, without resetting.
When doing a custom query you must reset after you've finished your loop like so:
$originalPost = $post;
$sidePosts = get_posts($queryArgs);
foreach($sidePosts as $post) {
setup_postdata($post);
// echo it out like a normal post.
}
$post = $originalPost;
or if you are using query_posts() (which you shouldn't in a sidebar):
wp_reset_query();
Which will take your post back to it's previous value.
For a custom page template please use the following to get everything correct
<?php
/* Template name: My custom template */
get_header();
if ( have_posts() ) while ( have_posts() ) : the_post();
the_title();
the_content()
endwhile;
get_sidebar();
get_footer();
?>
I just installed Views module for Drupal 7 and am trying to find out how to customize it.
So far, I have done the following things.
Created a content type specified views and named it as 'videotest'.
Created a custom theme as 'views-view-list--videotest.tpl.php'
The page is working without a problem.
Here is the custom template code I used (this is the default template from Views):
<?php print $wrapper_prefix; ?>
<?php if (!empty($title)) : ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php print $list_type_prefix; ?>
<?php foreach ($rows as $id => $row): ?>
<li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>
<?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>
How do I prevent Views to format $row for me? I like to format each values in a node myself using foreach.
I tried to set the view style as 'unformatted' with unformatted custom template, but it also style each value for me.
You should to use fields templates not 'Display', 'Style', or 'Row'.
Or you can use both fields in 'Row' template. Ex:
print $fields['you_field_value']->raw;
Name of 'you_field_value' show as part of link in fields list of view display.
Or to get the value of field:
print $fields['field_pretitle_front']->content;
print $fields['your_field_value']->raw;
did not work for me, however the following did in my case.
$row->field_YOUR_FIELD[0]['rendered']['#markup'];
I'm trying to have a post from a certain category display on my static homepage.
I seem to everything working just how I'd like with one exception.
I'd like the post to included the standard Continue reading (<!--more-->) link, but I can't seem to get it to work on my homepage instead all the post's content is displayed.
Here's the code I'm using to display the one post from a catagory on my home page:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
How do I get the <!--more--> tag to work correctly with the above code?
The <!--more--> quicktag generally doesn't work on anything other than the Home page. Try following the advice here under "How to Read More in Pages", i.e. like this:
<?php
global $more;
$more = 0;
?>
//The code must be inserted ahead of the call to the content
Then continue as you were:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
You'll need to set $more to 0 before every the_content() call;
It resets every time it hits the loop.
The discussion topic referenced from that Codex entry talks about exactly the problem you're solving, I think.
I was able to find some information here: http://codex.wordpress.org/Function_Reference/the_content
Found these lines which seem to do the trick:
global $more; // Declare global $more (before the loop).
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content("Read More");
Added the information to my code and everything work! Added in the Read More link when the more tag was added to the post.
Here's my final code:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php global $more;
$more = 0;
the_content("Read More");
?>