Title: Need help using WordPress like a CMS
Last modified: August 19, 2016

---

# Need help using WordPress like a CMS

 *  Resolved [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * (@madeoflegos)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/)
 * Brief-
    I am trying to use WordPress as a CMS to display my portfolio work.As
   a reference, I am trying to implement functionality similar to this [site](http://grapefruitgraphics.com/).
   I have added Custom Fields to store images in and here is the Loop that I am 
   using on my Static Home page Template.
 *     ```
       <?php if (have_posts()) : ?>
               <?php query_posts('category_name=portfolio&showposts=4'); ?>
               <?php while (have_posts()) : the_post(); ?>
                   <div class="recent_item_home" id="post-<?php the_ID(); ?>">
                       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                       <a href="#<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
                       <?php echo '<img class="recent_item_home_thumb" src="'.get_post_meta($post->ID, 'thumbnail', TRUE).'" />';?>
                       </a>
                   </div>
               <?php endwhile; ?>
           <?php else : ?>
       <?php endif; ?>
       ```
   
 * The main issue I am having is creating a relative link to the portfolio category
   with an anchor tag pointing to the post. I am currently using the function the_permalink()
   for the URL but this is not what I want. When I use the function the_permalink()
   to build the link I get an absolute path and when I click the link it takes me
   to a single post post page.
 * What I would like to happen:
    -  A front page that pulls 4 of the latest posts from the portfolio category–
      just to display a thumbnail image and maybe a title. almost there.
    -  Needs to have the link created in The Loop dynamically but unsure how to 
      implement.
    - desired link format- category/portfolio/#post_ID
 * Any help and or comments appreciated. Also, If there is a better way to implement
   a portfolio using WordPress please let me know.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695734)
 * That would be easy enough to do. On your portfolio category template or front
   page or wherever the posts are displaying, surrounding each post entry, you make
   anchors for each post like so (in the Loop):
 * `<div id='post-<?php the_ID(); ?>'>`
 * Then you just make your links elsewhere using the same approach:
    `<a href="/
   category/portfolio/#post-<?php the_ID(); ?>">`
 * Note that the default theme uses this exact method everywhere. In all the Loops,
   every post is surrounded by a div that looks just like this:
    `<div class="post"
   id="post-<?php the_ID(); ?>">`
 * That ID is an anchor. You can link directly to it with #post-ID.
 *  Thread Starter [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * (@madeoflegos)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695739)
 * Otto42,
 * Thanks for your quick response. That is what I needed. It is funny how simple
   it was to resolve…
 *  Thread Starter [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * (@madeoflegos)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695840)
 * Can I reopen this thread (please let me know if it is a problem)…
 * I have ran into another issue.
 * If I have a post on my front page and lets say that its true relative link is/
   category/portfolio/page/2/post-10
 * how can I dynamically create a link to this page?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695875)
 * You can’t. There’s no way to tell what page the post will be on beforehand.
 *  Thread Starter [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * (@madeoflegos)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695881)
 * Otto42,
 * Is there a way to reference the post limit set in the WordPress Admin menu.
 * if so I could create a loop that builds the link with the appropriate page like
   this:
 * Pseudo code:
 *     ```
       The loop
          if (have_posts());
             $page_limit = get page post limit from WordPress;
             $ count = 1; 
   
          while (have_posts()) : the_post();
             //build navigation
   
             if ($count <= $page_limit)
                echo '<a href="category/portfolio/#post-' . the_ID(). '"> 
   
             else
                $the_page = ($count / $page_limit)round down + 1; // example $count =7 and $page_limit =6  7/6 = 1.16 round down and get 1, then add 1 and $the_page = 2 (hope that makes sense)
   
                echo '<a href="category/portfolio/page/' . $the_page . '/#post-' . the_ID(). '">
   
             End else
             $count ++;
          End while
       End IF
       ```
   
 * Sorry about more poor Pseudo code, it is about as clear as mud.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695882)
 * Actually, you can never have such a link in WP as you stated:
    _/category/portfolio/
   page/2/post-10_
 * It will be either:
    /category/portfolio/page/2/ or example.com/post-10 best case:
   example.com/portfolio/post-10
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695895)
 * You can use `get_query_var('posts_per_page')` to get the number of posts that
   it is trying to show on the current page. This number will change depending on
   circumstances.
 * The actual setting from the admin menu can be retrieved with `get_option('posts_per_page')`.
 * moshu: He meant `/category/portfolio/page/2/#post-10`. The hash mark was just
   missing.
 *  Thread Starter [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * (@madeoflegos)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695899)
 * Otto42,
 * Thanks again for the great help. Issue Resolved.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Need help using WordPress like a CMS’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 3 participants
 * Last reply from: [madeoflegos](https://wordpress.org/support/users/madeoflegos/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/need-help-using-wordpress-like-a-cms/#post-695899)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
