Avatar art.webb asked

Using Wordpress "Template" feature to have "Posts" in "Pages"

Hi- long time Joomla user, now in Wordpress and there's one feature Joomla does out of the box that Wordpress doesn't:

Short story: I want a blogroll in a page. Why? Because I want a tidy "page" URL "example.com/blog/" -- as opposed to a "category posts" URL: "example.com/category/blog/"

Long story: I'm using the Wordpress "Template" feature (NOT theme, "Template") to have a "category of posts" in a "page". In other words, I want to have a "page", with a "category of posts" below the Page content. The Codex suggests to copy your index.php file when creating a "template.php" file, but I know YooTheme has a unique index.php file thanks to Warp. Here's the code I'm using, which ONLY displays the "category of posts" without ANY "Page content" (and if you share the page on Facebook the page's thumbnail or info doesn't display):

<?php  
/*  
Template Name: Template  
*/  
?>  
<?php  
$temp = $wp_query;  
$wp_query= null;  
$wp_query = new WP_Query();  
$wp_query->query('cat=9&showposts=0'.'&paged='.$paged);  
?>  

<?php  
$warp =& Warp::getInstance();  
echo $warp->template->render('template');

What will my template.php file look like if I'm supposed to use the index.php file to create my template file to have category posts display in a page below the page's content?

  • WordPress
  • Warp Theme
  • Radiance

Edited

5 Answers

2

Avatar aksel answered

Maybe I'm not understanding what you're trying to accomplish here (and i'm not part of the Yootheme crew btw), but if it's only 1 page you need to do this with, then can't you just as a quickfix:

  1. create a file named page-yourID.php in the theme root folder.

2: Insert your code...if you want the same layout as the yootheme page's/posts, simply copy it from there. So in your case i'd do for example:
<?php get_header();?>
// inserting single.php from yootheme
<div id="system">

    <?php if (have_posts()) : ?>  
        <?php while (have_posts()) : the_post(); ?>  

        <article class="item" data-permalink="<?php the_permalink(); ?>">  

            <header>  

                <h1 class="title"><?php the_title(); ?></h1>  

                <p class="meta">  
                    <?php  
                        $date = '<time datetime="'.get_the_date('Y-m-d').'" pubdate>'.get_the_date().'</time>';  
                        printf(__('Written by %s on %s. Posted in %s', 'warp'), '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'" title="'.get_the_author().'">'.get_the_author().'</a>', $date, get_the_category_list(', '));  
                    ?>  
                </p>  

            </header>  

            <div class="content clearfix"><?php the_content(''); ?></div>  

            <?php the_tags('<p class="taxonomy">'.__('Tags: ', 'warp'), ', ', '</p>'); ?>  

            <?php edit_post_link(__('Edit this post.', 'warp'), '<p class="edit">','</p>'); ?>  

            <?php if (pings_open()) : ?>  
            <p class="trackback"><?php printf(__('<a href="%s">Trackback</a> from your site.', 'warp'), get_trackback_url()); ?></p>  
            <?php endif; ?>  

            <?php if (get_the_author_meta('description')) : ?>  
            <section class="author-box clearfix">  

                <?php echo get_avatar(get_the_author_meta('user_email')); ?>  

                <h3 class="name"><?php the_author(); ?></h3>  

                <div class="description"><?php the_author_meta('description'); ?></div>  

            </section>  
            <?php endif; ?>  

            <?php comments_template(); ?>  

        </article>  

        <?php endwhile; ?>  
    <?php endif; ?>  
 // End of single.php   
// let's run our wp_query now  
$args = array(  
'cat' => 9,  
'showposts' => 0,  
'paged' => $paged  
);  
$the_query = new WP_Query( $args );  
  <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>  
// do something with our queryresult here  
<?php endwhile; ?>  
<?php   wp_reset_postdata(); ?>   
</div>  
                       <?php get_footer();?>  

Or if you simply want to remove the /category/ from your url all in all..I suppose you could do a rewrite in your .htaccess.

Make a backup of your .htaccess and try something like:

RewriteRule ^category/(.+)$ http://www.yourblog.com/872d38df4d8899ea4631fceaf18af433 [R=301,L]

Edit: the editor seems to mess up the rewriterule here...after yourblog.com/ it's supposed to only say $ 1 (no spaces).

If i totally misunderstood what you were trying to accomplish I appologize :) I'm as I said, no yootheme employee, simply another wordpresslover :D

Edited

0

Avatar karbo answered

Hi, the same issue here!
Anybody help us?
Thanks! :-)

0

Avatar david.carroll answered

@aksel - You ROCK!!! Thanks for sharing as much as you do in this community. :D. I do have some other suggestions to consider to drastically simplify your approach. Also, I would avoid the RewriteRule you suggested because it could cause issues with WordPress. See my notes below under the section: More Notes on Category Base in WordPress.

Art,

Regarding Much Delayed Answer:
My apologies for you having to wait so long to get a reply. Truth be told. I responded to this question not long after you originally posted it. However, my answer is not listed here. Now that I think about it, I may have opened your question with a number of other questions into separate tabs and responded one by one. After some time, the session times out and the response is not posted. I'm usually good about refreshing the session on questions that have been open for some time. It's possible I did not do this with your question. Anyway, my sincerest apologies for your long wait.

Regarding Your Question:
If I still understand your question as I did the first time, I believe you are asking for a way to modify the URL structure when viewing Posts in a Category. If that is the case, there is a native WordPress setting to consider.

Assuming you would like example.com/category/news/ to read example.com/blog/news/ you could change the Category Base as follows:

  • Step 1: Go to WP Admin
  • Step 2: Select Settings | Permalinks from the side menu.
  • Step 3: Locate Category Base text box and add the value blog or what ever you want to use.

More Notes on Category Base in WordPress:
If you are looking for a way to drop the Category Base altogether, then this will require some custom coding or a plugin to help facilitate the loading of specific categories to appear on specific pages. The purpose of the Category Base is for WordPress to understand the type of content being requested without having to use a less pretty URL like ?cat=3. /category_base/news/ is required for WordPress to resolve the request is ?cat=3 (assuming 3 is the ID for category named news).

Friendly Reminder: Please click the Checkmark next to the answer that best resolved your question. Also, click the +1 to all answers you think were helpful.

Best Regards,

David Carroll

Edited

0

Avatar thomas.cummings answered

'WordPress SEO by Yoast' offers out of the box support to strip the category base from the permalink. It is also widely accepted as the best supported seo plugin for wordpress.

Word of warning: if you strip the category base you must make sure a 'post' and 'page' do not have the same title as this will cause two duplicate permalinks.

-1

Avatar art.webb answered

I purchased a 3 month subscription just to ask this question as I've been using the "Master Theme" and couldn't figure this out so I basically rationalized paying for an answer on the support forums. Is this something that can be answered in the next two months? I understand your main background is Joomla, perhaps you could expedite this to a Wordpress savvy programmer? Much appreciated.

Know someone who can answer? Share a link to this question via email or twitter.